How to do it...

Follow these steps to implement the example:

  1. Implement a class named News. This class implements the elements sent from the publisher to the subscriber. It will have two private String attributes, named title and content, and a Date attribute named date. It will also have the methods to get and set the values of these attributes. The source code of this class is very simple, so it won't be included here.
  2. Create a class named Consumer and specify that it implements the Subscriber interface parameterized by the News class. It will have two private attributes: a Subscription object named subscription and a String attribute called name. Implement the constructor of the class to initialize the name attribute:
 public class Consumer ...

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.