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. First, implement a class that will simulate a text file. Create a class named FileMock with two attributes: a String array named content and int named index. They will store the content of the file and the line of the simulated file that will be retrieved:
        public class FileMock {            private String[] content;           private int index;
  1. Implement the constructor of the class that initializes the content of the file with random characters:
        public FileMock(int size, int length){           content = new String[size];           for (int i = 0; i< size; i++){             StringBuilder buffer = new StringBuilder(length);             for (int j = 0; j < length; j++){               int randomCharacter= (int)Math.random()*255;  buffer.append((char)randomCharacter); ...

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