Processing uncontrolled exceptions in a ForkJoinPool class
The fork/join framework gives you the possibility to set a handler for the exceptions thrown by the worker threads of a ForkJoinPool
class. When you work with a ForkJoinPool
class, you should understand the difference between tasks and worker threads.
To work with the fork/join framework, you implement a task extending the ForkJoinTask
class or, usually, the RecursiveAction
or RecursiveTask
classes. The task implements the actions you want to execute concurrently with the framework. They are executed in the ForkJoinPool
class by the worker threads. A worker thread will execute various tasks. In the work-stealing algorithm implemented by the ForkJoinPool
class, a worker thread looks for a new task when the task it was executing finishes its execution or it is waiting for the completion of another task.
In this recipe, you will learn how to process the exceptions thrown by a worker thread. You'll have to implement two additional elements...