[concurrency-interest] ThreadPoolExecutor question

Doug Lea dl@cs.oswego.edu
Wed, 29 Dec 2004 19:09:22 -0500


> 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);
}


-Doug