From Doug Lea:
Add allowCoreThreadTimeOut to ThreadPoolExecutor to optionally allow core thread to use keep-alive policy.
Here's the initial post that triggered this RFE:
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).
Another way to look at this: I want something like fixed thread pool
(Executors.newFixedThreadPool()) but with threads dying off when they
are idle for too long, and re-created when they are needed again.
Is there a simple way to achieve this, one might think, quite reasonable
###@###.### 2005-03-04 04:19:37 GMT