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, 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()

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