How to do it...

Follow these steps to implement the example:

  1. Create a class named ArrayGenerator. This class will generate an array of random integer numbers with the specified size. Implement a method named generateArray(). It will generate the array of numbers. It receives the size of the array as a parameter:
        public class ArrayGenerator {           public int[] generateArray(int size) {             int array[]=new int[size];             Random random=new Random();             for (int i=0; i<size; i++){               array[i]=random.nextInt(10);             }             return array;           } 
  1. Create a class named TaskManager. We will use this class to store all the tasks executed in ForkJoinPool used in the example. Due to the limitations of the ForkJoinPool and ForkJoinTask classes, you will use this class to ...

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.