How to do it...

Follow these steps to implement the example:

  1. Create a class named TaskFJ and specify that it extends the RecursiveAction class:
        public class TaskFJ extends RecursiveAction {
  1. Declare a private array of int numbers named array:
        private final int array[];
  1. Declare two private int attributes, named start and end:
        private final int start, end;
  1. Implement the constructor of the class to initialize its attributes:
        public TaskFJ(int array[], int start, int end) {           this.array=array;           this.start=start;           this.end=end;         }
  1. Implement the compute() method. If this task has to process a block of more than 1,000 elements (determined by the start and end attributes), create two TaskFJ objects, send them to the ForkJoinPool class ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.