Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
Do not submit tasks that do not support interruption using {{Thread.interrupt()}} to a thread pool if it is necessary to shutdownshut down the thread pool or to cancel individual tasks within it. According to the Java API interface \[[API 2006|AA. Java References#API 06]\], the {{java.util.concurrent.ExecutorService.shutdownNow()}} method

...

Because the task does not support interruption using the Thread.interrupt() method, there is no guarantee that the shutdownNow() method will shutdown shut down the thread pool. Using the shutdown() method does not fix the problem either because it waits until all executing tasks have finished.

Similarly, tasks that use some mechanism other than Thread.interrupted() to determine when to shutdown shut down will be unresponsive to shutdown() or shutdownNow(). For instance, tasks that check a volatile flag to determine whether it is safe to shutdown will be unresponsive to these methods. The guideline THI05-J. Do not use Thread.stop() to terminate threads provides more information on using a flag to terminate threads.

...