[concurrency-interest] ThreadPoolExecutor not shutting down

David Holmes davidcholmes at aapt.net.au
Thu Mar 18 20:43:47 EDT 2010


In general a ThreadPoolExecutor must be explicitly shutdown. Your
application needs to manage the TPE lifecycle. In later JDK versions you can
use the idle timeout on core threads to let all threads terminate.

A daemon thread factory will prevent the TPE from keeping the VM alive, but
at the risk of allowing submitted tasks to not be run or to be terminated in
the midst of execution - generally not a good thing.

A shutdown hook is of little help here as the hooks will only run if the VM
has decided to shutdown due to no user-threads (which can't be the case due
to the TPE), or System.exit has been called, in which case there's no need
to explicitly shutdown the TPE (it's about to get obliterated by process
termination), unless you want to manage the unfinished tasks.

HTH

David Holmes
  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Ben Manes
  Sent: Friday, 19 March 2010 10:35 AM
  To: Dibyendu Majumdar; concurrency-interest at cs.oswego.edu
  Subject: Re: [concurrency-interest] ThreadPoolExecutor not shutting down


  This sounds like you'd want to use daemon thread factory, use a shutdown
hook to stop the executor, or another approach to let the VM gracefully
exit.




----------------------------------------------------------------------------
--
  From: Dibyendu Majumdar <concurrency-interest at majumdar.org.uk>
  To: concurrency-interest at cs.oswego.edu
  Sent: Thu, March 18, 2010 3:05:34 PM
  Subject: [concurrency-interest] ThreadPoolExecutor not shutting down

  I am running Java 1.5 on Mac OS X Tiger - and I think that the
ThreadPoolExecutor code is a very old version. The pool is not shutting
down; by running through the debugger I can see that all idle threads are
blocked on a queue, and the shutdown sequence does not interrupt idle
threads.
  Is there any way I can run a more up-to-date version with Java 1.5?
  Is there a known workaround to this issue?

  Many thanks

  Regards
  Dibyendu





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100319/1ceba953/attachment.html>


More information about the Concurrency-interest mailing list