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 it works...

In this example, we implemented a reactive streams communication between a publisher and a subscriber using the interfaces provided by the Java 9 API and just followed the expected behavior defined in the reactive streams' specification.

We had a publisher implemented by the MyPublisher class and subscribers implemented by the Consumer class. There are subscriptions between the publishers, and each subscriber is implemented by the MySubscription object.

The cycle of the communication starts when a subscriber calls the subscribe() method of a publisher. The publisher has to create the subscription between them and send that subscription to the subscriber using the onSubscribe() method. The subscriber must use the request() ...

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