Versions Compared

Key

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

Wiki Markup
Programs may submit _only_ tasks that support interruption using {{Thread.interrupt()}} to thread pools that require the ability to shut down the thread pool or to cancel individual tasks within the pool. Programs must not submit tasks that lack interruption support to such thread pools. According to the Java API interface \[[API 2006|AA. Bibliography#API 06]\], the {{java.util.concurrent.ExecutorService.shutdownNow()}} method

...attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.

...

.

Noncompliant Code Example (Shutting Down Thread Pools)

...

The shutdownNow() method may fail to shut down the thread pool because the task lacks support for interruption using the Thread.interrupt() method. Use of , and because the shutdown() method also fails to fix the problem because it waits must wait until all executing tasks have finished.

Similarly, tasks that use some mechanism other than Thread.interrupted() to determine when to 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 are unresponsive to these methods. The rule THI05-J. Do not use Thread.stop() to terminate threads provides more information on using a flag to terminate threads.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d83958a4c911b3eb-b104fb19-4b6c4626-b3358f55-18d9a10de20606d8e8344105"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

interface ExecutorService

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="431686b1f2ae746b-11d9af30-47ee47c8-9d4ab795-388036e4b423c729b9626cce"><ac:plain-text-body><![CDATA[

[[Goetz 2006

AA. Bibliography#Goetz 06]]

Chapter 7, Cancellation and Shutdown

]]></ac:plain-text-body></ac:structured-macro>

...