DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Java
  4. Java 9 (Part 5): Flow With the New Reactive Streams, First Look

Java 9 (Part 5): Flow With the New Reactive Streams, First Look

The Reactive streams API will undergo a name change in Java 9. This quick guide will walk you through everything you need to know about it.

Tomer Ben David user avatar by
Tomer Ben David
·
May. 01, 17 · Tutorial
Like (7)
Save
Tweet
Share
13.44K Views

Join the DZone community and get the full member experience.

Join For Free

Welcome back to my Java 9 series! We are going to cover another cool and new concept in Java 9 — a concise interface for Reactive streams, which contains the ability for non-blocking back pressure. You see, Reactive streams are all around us in all up-to-date languages and libraries. The main challenge, however, in Reactive streams is not the implementation, but a concise interface. Let's see how Java 9 will handle it.

Image title

Java 9 Reactive Streams

The main components of Java 9 Reactive streams are:

  1. Publisher
  2. Subscriber
  3. Subscription

In short, the subscriber subscribes to the publisher on a subscription to receive the stream.

For that, we have multiple methods such as:

  1. Publisher::subscribe
  2. Subscriber::onNext
  3. Subscriber::onSubscription
  4. Subsription::request

The names are rather self explanatory which is great.

Implementing Flow

By now, you should call Reactive streams –> Flow. In order to implement such a stream, you need to implement: Publisher, Subscriber, Subscription.

Create the publisher:

SubmissionPublisher<Integer> publisher = new SubmissionPublisher<>();


Create the subscriber:

public class MySubscriber implements Flow.Subscriber<String> {
    private Subscription subscription;

    @Override public void onSubscribe(Flow.Subscription subscription) { // implemnet }
    @Override public void onNext(Integer item) { // implemnet }
    @Override public void onError(Throable t) { // implemnet }
    @Override public void onComplete() { // implemnet }
}


So all we needed to do was to create a publisher, then create a subscriber. Note that the subscriber should have a subscription member. Then, the Subscriber implements all the methods related to the flow API:

  1. onSubscribe
  2. onNext
  3. onError
  4. onComplete

Summary

In part 5, we saw that the Reactive streams API has become much better and is called the Flow API. This API is concise and includes three main components: publisher, subscriber, and subscription, with subscriber implementing the methods for receiving the stream and notifying on errors.

Reactive Streams Stream (computing) Java (programming language) Flow (web browser)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Required Knowledge To Pass AWS Certified Data Analytics Specialty Exam
  • Explainer: Building High Performing Data Product Platform
  • New MacBook Air Beats M1 Max for Java Development
  • Simulating and Troubleshooting StackOverflowError in Kotlin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: