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

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