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 Item that will represent the items of information sent from the publisher to the subscribers. This class has two String attributes, named title and content, and the methods to get() and set() their values. Its source code is very simple, so it won't be included here.
  2. Then, create a class named Consumer1 and specify that it implements the Subscriber interface parameterized with the Item class. We have to implement four methods. First, we implement the onComplete() method. It simply writes a message to the console:
        public class Consumer1 implements Flow.Subscriber<Item> {            @Override           public void onComplete() {  System.out.printf("%s: Consumer 1: Completed\n", ...

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