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 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 ...

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