Customizing tasks running in the fork/join framework
The Executor
framework separates task creation and its execution. With it, you only have to implement the Runnable
objects and use an Executor
object. You just need to send the Runnable
tasks to the executor and it creates, manages, and finalizes the necessary threads to execute these tasks.
Java 9 provides a special kind of executor in the fork/join framework (introduced in Java 7). This framework is designed to solve problems that can be broken down into smaller tasks using the divide and conquer technique. Inside a task, you have to check the size of the problem you want to resolve; if it's bigger than the established size, you divide the problem into two or more tasks and execute them using the framework. If the size of the problem is smaller than the established size, you resolve the problem directly in the task; optionally, it returns a result. The fork/join framework implements the work-stealing algorithm that improves the overall...