How to do it...

Follow these steps to implement the example:

  1. First, let's implement some auxiliary classes we will use in the example. Implement the Person class to store some basic data about a person and the PersonGenerator class to generate a random list of persons. You can check the Creating streams from different sources recipe to see the source code of both the classes.
  2. In that class, override the toString() method with the following code, which returns the first name and the last name of the person:
        @Override         public String toString() {           return firstName + " " + lastName;         }
  1. Then, create a class named Counter with two attributes: a String attribute named value and an int attribute named counter. Generate the methods to get()

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.