[concurrency-interest] ThreadPoolExecutor question

Dawid Kurzyniec dawidk@mathcs.emory.edu
Wed, 29 Dec 2004 20:51:06 -0500


Doug Lea wrote:

>>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.
>>    
>>
>
>One way to get this effect is to make a subclass of ThreadPoolExecutor
>in which you use a short keep-alive, but override execute as
>
>public void execute(Runnable r) {
>   prestartCoreThread(); // does nothing if already at core
>   super.execute(r);
>}
>
>  
>
Hmmm... But if I set core size to 0, the above will have no effect; and 
when I set core size to max, the workers will not die out, isn't that 
right? It seems to me that using "addIfUnderMaximumPoolSize" would maybe 
work, but this method is private...

Regards,
Dawid