From the course: Parallel and Concurrent Programming with Java 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Divide and conquer: Java demo

Divide and conquer: Java demo - Java Tutorial

From the course: Parallel and Concurrent Programming with Java 2

Start my 1-month free trial

Divide and conquer: Java demo

- [Instructor] To demonstrate how to implement a parallel divide and conquer algorithm, I'll be using Java's Fork/Join Framework, which is designed to use multiple processors to execute work that can be recursively broken down into smaller pieces. At the heart of the framework is an executor service called the ForkJoinPool, which distributes tasks to its worker threads. It executes ForkJoinTasks, which include methods named Fork and Join. We use the fork method when recursively breaking down a problem, to asynchronously execute tasks with the ForkJoinPool, and then, during the combine stage, we use the join method, which returns the result of the task when it's done. ForkJoinTasks are typically created using one of two specialized classes, either the RecursiveTask class, which can return a result, or the RecursiveAction class, which does not. To demonstrate how to write a parallel divide and conquer algorithm using recursion, and the Fork/Join framework, I'll create an example program…

Contents