O'Reilly logo

Mastering Concurrency Programming with Java 8 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

Summary

The divide and conquer design technique is a very popular approach to solve different kinds of problems. You divide the original problem into smaller problems and those problems into smaller ones until we have enough simple problems to solve it directly. In version 7, the Java concurrency API introduced a special kind of Executor optimized for these kinds of problems. It's the Fork/Join Framework. It's based on the following two operations:

  • fork: This allows you to create a new child task
  • join: This allows you to wait for the finalization of a child task and get its results

Using those operations, Fork/Join tasks have the following appearance:

if ( problem.size() > DEFAULT_SIZE) { childTask1=new Task(); childTask2=new Task(); childTask1.fork(); ...

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