Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Java 9’s java.util.concurrent.Flow package provides the JDK’s interfaces for the Reactive Streams protocol: publishers send items, subscribers signal demand, and subscriptions connect the two. It is an interoperability contract, not a full stream-processing library with operators such as map or filter.

What is Reactive Streams in Java 9?

Reactive Streams is a JVM standard for asynchronous streams that use non-blocking backpressure. Java 9 exposes its central roles through java.util.concurrent.Flow. The JDK API describes the publisher/subscriber interaction; the specification defines the protocol those participants follow. See the Java SE 9 Flow.Publisher API and the Reactive Streams JVM specification.

Type Role
Flow.Publisher<T> Produces sequenced items in response to subscriber demand.
Flow.Subscriber<T> Receives subscription, item, error, and completion callbacks.
Flow.Subscription Connects one publisher and subscriber; the subscriber requests items or cancels the subscription.
Flow.Processor<T,R> Acts as both subscriber and publisher, allowing it to sit between upstream and downstream stages.

A publisher can serve multiple subscribers, each with its own subscription and demand. The protocol for each subscription is onSubscribe, followed by zero or more onNext calls, and optionally a terminal onError or onComplete. Signals for a subscription must be serialized rather than delivered concurrently. A failure is reported through onError; a finite successful stream ends with onComplete.

How does backpressure work in Java Flow?

Backpressure is explicit accounting for demand, not a guarantee that Flow will physically slow every source. In onSubscribe, a subscriber receives a Flow.Subscription. It calls request(n) to authorize up to n more items, or cancel() to stop receiving them. A publisher must not call onNext more times than the subscriber has requested.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A subscriber can request items individually, which gives it fine-grained control but requires more coordination, or request a batch, which can reduce request overhead. The publisher can deliver only within outstanding demand; the subscriber requests more as it is ready to continue processing.

This protocol helps coordinate asynchronous components and bound work, but it does not automatically make an application memory-safe. A publisher may buffer items, and a source such as an external event feed may not be capable of slowing down when demand is low. In those cases, the implementation needs an appropriate bounded-buffering or dropping policy. Actual memory use depends on the source, buffering strategy, and demand choices; Flow does not choose those policies for an application.

What is the difference between Flow and Reactive Streams?

Reactive Streams is the specification; Flow is the JDK’s Java API surface for its core protocol. The Java 9 Flow interfaces correspond to the specification’s publisher, subscriber, subscription, and processor roles, but they use the java.util.concurrent.Flow package. The separate Reactive Streams API uses the org.reactivestreams package.

Neither set of interfaces is, by itself, a complete stream-processing toolkit. The specification focuses on mediating streams between components and does not prescribe a particular set of manipulation operators. Transformations such as mapping, filtering, merging, and execution or materialization facilities are provided by libraries. Java 9 also includes SubmissionPublisher, a concrete JDK publisher implementation; that does not turn Flow into an operator library.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I connect a Java 9 Flow Publisher to a stream library?

Check the library’s documentation for the exact version and JDK baseline you use. Libraries may expose adapters or factories to bridge java.util.concurrent.Flow and org.reactivestreams, but names and supported combinations are library-specific.

For example, Apache Pekko 2.0 documents Java 9-and-later Flow support and uses JavaFlowSupport for the JDK types; its documentation also distinguishes the separate org.reactivestreams API used with Java 8. This is Pekko-specific guidance, not a universal adapter name. Consult Apache Pekko 2.0 Reactive Streams interop documentation for the supported factories and types, then verify that the chosen artifact versions match your project.

  • If you need only compatible publisher/subscriber interfaces, the JDK Flow types may be sufficient.
  • If you need operators, stream execution, or materialization, use a library that provides those features and check its Flow integration.
  • If the library expects org.reactivestreams while your code exposes Flow types, use that library’s documented bridge rather than assuming the interfaces can be substituted directly.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How can I validate a Flow implementation?

The Reactive Streams project provides a Flow-specific TCK for the Java 9 interfaces. Its README describes publisher verification, subscriber white-box and black-box verification, and identity-processor verification, and requires at least Java 9. Match the TCK dependency version to the API or implementation version you are validating; the README’s example artifact version should not be treated as a current-version recommendation.

The TCK is useful conformance coverage, not a complete proof: its documentation explicitly notes that some specification rules cannot practically be automated. Combine it with tests for your implementation’s own buffering, cancellation, error handling, and source behavior. See the Flow TCK documentation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.