DEV Community

loading...

Java 9 Flow API – Reactive Streams

loizenai profile image loizenai ・2 min read

https://grokonez.com/java/java-9/java-9-flow-api-reactive-streams

Java 9 Flow API – Reactive Streams

Java 9 introduces Reactive Streams under java.util.concurrent.Flow that supports an interoperable publish-subscribe framework. In the tutorial, we're gonna look at a general view of Reactive Streams and how it comes to Java 9 with some new Flow API Components.

Related Articles:

I. Reactive Streams

1. Overview

Reactive Streams aims to improve concurrency workflows for developers by solving the pain of back-pressure (when fast data source doesn't overwhelm the stream destination).

reactive-stream-backpressure

In the image above, we can see that if Destination can not deal with incoming data from Source, all future data could be blocked until the existing ones are processed.

If the Source checks when Destination is not overflowed to send data, the problem could be solved. But in this case, it is still synchronous communication and we don't take advantage of an asynchronous system which enables the parallel use of computing resources, on collaborating network hosts or multi-core processor.

Reactive Streams processes an asynchronous stream data across an asynchronous boundary (passing elements on to another thread or thread-pool), and receiving side (Destination) is not forced to buffer arbitrary amounts of data, then buffer overflow will not occur.

In summary, Reactive Streams:

  • process a potentially unbounded number of elements
  • in sequence,
  • asynchronously passing elements between components,
  • with mandatory non-blocking back-pressure.

These things are possible by flow control and the publish-subscribe pattern which allows the subscriber to be able to understand limitation and show publisher its capacity.

More at:

https://grokonez.com/java/java-9/java-9-flow-api-reactive-streams

Java 9 Flow API – Reactive Streams

Discussion (0)

pic
Editor guide