[concurrency-interest] Timeout threadpool

Joe Bowbeer joe.bowbeer at gmail.com
Thu Mar 16 14:29:08 EST 2006


On 3/16/06, jason rutherglen <jasonhusong at yahoo.com> wrote:
>
> Is there an implementation of a threadpool that times out?  Is there an
> implementation that keeps track of the time a Callable has been running?  I
> have already started writing my own however I was wondering if anyone else
> has some ideas.
>

I think the c-i archives contain some discussion about this.

Two approaches are:

1. Use an auxilary ScheduledExecutor or Timer to cancel tasks
submitted to the primary executor.  The primary task could submit its
own cancellation task when it starts executing, and then cancel its
own cancellation task if it (the primary task) finishes before time
runs out.  Or, depending on how the timeout is supposed to work, the
cancellation task could be submitted at the same time the primary task
is submitted.

2. The task times its own execution using a 2nd thread.  See
TimedCallable in Doug Lea's old concurrency utils:

http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html

Joe.



More information about the Concurrency-interest mailing list