O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition 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

How to do it...

Follow these steps to implement the example:

  1. Create a class named Task. Specify that it implements the RecursiveTask class, parameterized with the Integer class:
        public class Task extends RecursiveTask<Integer> { 
  1. Declare a private int array named array. It will simulate the array of data you are going to process in this example:
        private int array[]; 
  1. Declare two private int attributes named start and end. These attributes will determine the elements of the array this task has to process:
        private int start, end; 
  1. Implement the constructor of the class that initializes its attributes:
        public Task(int array[], int start, int end){           this.array=array;           this.start=start;           this.end=end;         } 
  1. Implement the compute()

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