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

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.