Java Reference
In-Depth Information
7.2.5. Limitations of Shutdownnow
When an ExecutorService is shut down abruptly with shutdownNow , it attempts to
cancel the tasks currently in progress and returns a list of tasks that were submitted but never
started so that they can be logged or saved for later processing. [5]
However, there is no general way to find out which tasks started but did not complete. This
means that there is no way of knowing the state of the tasks in progress at shutdown time
unless the tasks themselves perform some sort of checkpointing. To know which tasks have
not completed, you need to know not only which tasks didn't start, but also which tasks were
in progress when the executor was shut down. [6]
TrackingExecutor in Listing 7.21 shows a technique for determining which tasks were
in progress at shutdown time. By encapsulating an ExecutorService and instrumenting
execute (and similarly submit , not shown) to remember which tasks were cancelled after
shutdown, TrackingExecutor can identify which tasks started but did not complete nor-
mally. After the executor terminates, getCancelledTasks returns the list of cancelled
tasks. In order for this technique to work, the tasks must preserve the thread's interrupted
status when they return, which well behaved tasks will do anyway.
Search WWH ::




Custom Search