Follow these steps to implement the example:
- Create a class named TaskFJ and specify that it extends the RecursiveAction class:
public class TaskFJ extends RecursiveAction {
- Declare a private array of int numbers named array:
private final int array[];
- Declare two private int attributes, named start and end:
private final int start, end;
- 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; }
- 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 ...