Versions Compared

Key

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

...

Wiki Markup
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 when a task concludes successfully by executing all statements in its {{run()}} method or halts because of an exception. ({{java.lang.Error}} might not be captured on specific implementations. See [Bug ID 6450211|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6450211] for more information \[[SDN 2008|AA. Java References#SDNBibliography#SDN 08]\]).  When using this approach, substitute the executor service with a custom {{ThreadPoolExecutor}} that overrides the {{afterExecute()}} hook as shown below:

...

Wiki Markup
The {{ExecutorService.submit()}} method can be used to submit a task to a thread pool instead of the {{execute()}} method to obtain a {{Future}} object.  Note that the uncaught exception handler is not called if {{ExecutorService.submit()}} is invoked. This is because the thrown exception is considered to be part of the return status and is consequently wrapped in an {{ExecutionException}} and re-thrown by {{Future.get()}} \[[Goetz 2006|AA. Java References#GoetzBibliography#Goetz 06]\].

Compliant Solution (Future<V> and submit())

...

Wiki Markup
\[[API 2006|AA. Java References#APIBibliography#API 06]\] interfaces {{ExecutorService}}, {{ThreadFactory}} and class {{Thread}}
\[[Goetz 2006|AA. Java References#GoetzBibliography#Goetz 06]\] Chapter 7.3: Handling abnormal thread termination

...