...
Task-specific recovery or clean-up actions can be performed by overriding the afterExecute()
hook of the java.util.concurrent.ThreadPoolExecutor
class. This hook is called either when a task concludes successfully by executing all statements in its run()
method or when the task halts because of an exception. Some implementations may fail to catch java.lang.Error
. (See Bug ID 6450211 for more information [SDN 2008].) When using this approach, substitute the executor service with a custom ThreadPoolExecutor
that overrides the afterExecute()
hook:
...
The ExecutorService.submit()
method can be used (in place of the execute()
method) to submit a task to a thread pool and obtain a Future
object. When the task is submitted via ExecutorService.submit()
, thrown exceptions never reach the uncaught exception handler because the thrown exception is considered to be part of the return status and is consequently wrapped in an ExecutionException
and rethrown by Future.get()
[Goetz 2006a].
Compliant Solution (Future<V>
and submit()
)
...
Bibliography
[API 2006] | Interfaces |
Chapter 7.3, Handling Abnormal Thread Termination |
...