How to do it...

Follow these steps to implement the example:

  1. Start the example by implementing two auxiliary classes. First, create a class named MatrixMock. This class will generate a random matrix of numbers between one and 10, where the threads will look for a number:
        public class MatrixMock {
  1. Declare a private int matrix named data:
        private final int data[][];
  1. Implement the constructor of the class. This constructor will receive the number of rows of the matrix, the length of each row, and the number we are going to look for as parameters. All the three parameters are of the type int:
        public MatrixMock(int size, int length, int number){
  1. Initialize the variables and objects used in the constructor:
        int counter=0;  data=new ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.