[concurrency-interest] ThreadPoolExecutor question

Gregg Wonderly gregg.wonderly@pobox.com
Wed, 29 Dec 2004 22:06:15 -0600

Dawid Kurzyniec wrote:
> I would like to use a thread pool that is 1) bounded, but 2) does NOT 
> keep any threads (and JVM) alive if there are no requests for 
> sufficiently long time (e.g. 30s). When the pool gets contended (i.e. 
> maximum number of used worker threads is reached), I would like it to 
> start enqueuing subsequent tasks rather than rejecting them. The most 
> intuitive approach - set core size to 0, maximum pool size to the 
> bounding value, and the queue to some kind of LinkedQueue or ArrayQueue 
> - fails: no tasks get executed at all (consistently with Javadoc but - 
> IMHO - a little bit counterintuitively).

Aside from whether the tools can be convinced to work this way, the 
primary issue with disallowing threads to execute is that you can create 
distributed deadlock.  A thread that you are not allowing to run might 
be the one needed to allow the running threads to finish.  With this in 
mind, threaded designs should try not to allow threads that depend on 
each other run in the same pool where thread count throttling is used. 
There are many subtle issues that you need to consider when partioning 
an application in to threads and when using thread pools to control the 
total load on a system.

Gregg Wonderly