[concurrency-interest]RE: comments on Executor

Miles Sabin msabin@interx.com
Sun, 3 Feb 2002 08:20:34 -0000

Doug Lea wrote,
> The main interaction with Executor classes is that any interrupted 
> thread should normally be discarded from the pool and replaced with 
> fresh one. Doing this regularly makes thread pools less efficient 
> than using a thread per task.

What's the rationale for this?

The only things I can think of that discarding the thread helps with 
are ThreadLocals which might be left in inconsistent states by 
cancellation. But surely that's just a special (and perhaps relatively 
uncommon) case of general global state needing to be managed carefully 
in cancellable contexts?

So, if in the general case tasks have to clean up on cancellation,
then why not also require them to do threadLocal.set(null), or
something equivalent, if cancellation has left threadLocal in a bad 



Miles Sabin                                     InterX
Internet Systems Architect                      27 Great West Road
+44 (0)20 8817 4030                             Middx, TW8 9AS, UK
msabin@interx.com                               http://www.interx.com/