O'Reilly logo

Java 7 Concurrency Cookbook by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Fork/Join pool

In this recipe, you will learn how to use the basic elements of the Fork/Join framework. This includes:

  • Creating a ForkJoinPool object to execute the tasks
  • Creating a subclass of ForkJoinTask to be executed in the pool

The main characteristics of the Fork/Join framework you're going to use in this example are as follows:

  • You will create ForkJoinPool using the default constructor.
  • Inside the task, you will use the structure recommended by the Java API documentation:
    If (problem size > default size){
      tasks=divide(task);
      execute(tasks);
    } else {
      resolve problem using another algorithm;
    }
  • You will execute the tasks in a synchronized way. When a task executes two or more subtasks, it waits for their finalizations. By this way, the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required