[concurrency-interest] Questions about ThreadPoolExecutor

Brian Goetz brian at quiotix.com
Wed Mar 1 17:26:49 EST 2006


>     1)  I need to have the pool customized such when I invokeAll on a 
> Collection of Callables, I also get to specify how many threads I want 
> to allocate to run this Collection of Callables.

You can create a custom Executor for each batch of Callables.  You will 
probably want to use some other bounding mechanism to ensure that 
aggregate number of threads created by such executors doesn't exceed 
some threshold.

>     2) The run() method of the runnable (say A) that I submit to the 
> pool might create other runnables (say a and b) which will in terms be 
> submitted to the same pool.  

This is deadlock-prone unless the _pool_ is unbounded (or you can prove 
that the number of tasks submitted will be less than the pool size.)

> However, it looks like 
> using SynchronusQueue requires the pool to be unbounded which I don't 
> want.  I want a bounded pool.

SynchronousQueue works best with unbounded pools; with bounded pools, it 
will invoke the rejected execution handler to dispose of tasks submitted 
in excess of the pool size.

Unless you can bound the task count somehow, you cannot have both of 
what you want -- either bound the pool, or don't use tasks that depend 
on other tasks.  Otherwise, you're playing Deadlock Roulette.

> Any suggestion on how I can achieve these two criteria using the 1.5 
> concurrency Executor. 

Tell us more about the _problem_ you are trying to solve, rather than 
the solution you have in mind, and we could probably help further.




More information about the Concurrency-interest mailing list