How to do it...

Follow these steps to implement the example:

  1. Create a class named DocumentMock. It will generate a string matrix that will simulate a document:
        public class DocumentMock { 
  1. Create an array of strings with some words. This array will be used in the generation of the strings matrix:
        private String words[]={"the","hello","goodbye","packt",                                "java","thread","pool","random",                                "class","main"}; 
  1. Implement the generateDocument() method. It receives as parameters the number of lines, the number of words per line, and the word the example is going to look for. It returns a matrix of strings:
        public String[][] generateDocument(int numLines, int numWords,                                           String word){ 
  1. First, create the necessary objects to generate the document-the ...

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.