[concurrency-interest] Questions about ThreadPoolExecutor

Brian Goetz brian at quiotix.com
Thu Mar 2 16:32:42 EST 2006

> newCachedThreadPool would get you the synchronous queue, but I think
> you'll need to invoke one of the ThreadPoolExecutor constructors
> yourself regardless, because none of the Executors factory methods
> provides everything you need, and you'll need a real
> ThreadPoolExecutor in order to configure the queue, maximum pool size,
> rejected execution handler, and keep-alive time.

This would work too, but doesn't give you a chance to bound the 
aggregate thread count.

You could bound the aggregate thread count using a cached thread pool 
and a second semaphore; one that requests nThread permits from the 
master semaphore before starting an invokeAll, and returns them when 
done.  That way, you could still say "Allow no more than N task 
threads", and if too many batches are submitted, they block.

More information about the Concurrency-interest mailing list