How to use Java 9 Flow Interfaces / what's the point of including them in Java 9?

user140547 :

First I have to say that I have not much experience with Reactive Programming.

Since there are only a few interfaces in JDK 9 (Flow and its nested interfaces), JDK 9 obviously does not include a reactive library like RxJava.

In the Javadoc, there are some examples for implentations of Publisher, Subscription, and Subscriber. But these seem to be quite low-level and do not have any reactive operators or handling of back-pressure.

So what is the point of including those interfaces into the JDK?

Are vendors of reactive libraries supposed to use them, so that Java implementations (like RxJava) of those use a common set of interfaces? (similar to JPA and Hibernate?)

akarnokd :

It mainly allows Java itself to use reactive programming internally in some future version, such as Reactive JDBC, Networking, IO, etc. In concept, it also serves as a new rally point for interoperation, however, such rally point already exists with Reactive Streams targeting a much larger audience via its Java 6 requirement.

As you mentioned, having that 4 interfaces and the SubmissionPublisher by itself has limited use. If Java had extension methods similar to Kotlin and C#, the inclusion of the interfaces could have much more interesting impact.

Unfortunately, it also means that existing libraries have to use bridges to convert between Java 9 Flow and Reactive-Streams and/or reimplement the whole library with Java 9 Flow API - cutting out anybody without Java 9 (i.e., Android).

Major libraries have already such bridges (RxJava 2 Jdk 9 Interop, Reactor-Core Interop) and the Reactive-Streams will have its own bridge eventually. There is also a prototype reactive library written for and with Java 9 features.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=464187&siteId=1