How to use Java 9 streaming interfaces / what is the point of their inclusion in Java 9?

First I have to say that I have little experience with reactive programming.

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

Javadoc has some examples for Publisher , Subscription and Subscriber implants. But they seem rather low-level and have no jet operators or back pressure.

So what is the point of including these interfaces in the JDK?

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

+5
source share
2 answers

Basically, this allows Java itself to use reactive programming inside any future version, for example, Reactive JDBC, Networking, IO, etc. In concept, this also serves as a new rally point for interaction, however such a rally point already exists with jet streams aimed at a much wider audience on demand of Java 6.

As you mentioned, the use of these 4 interfaces and SubmissionPublisher itself is limited. If Java had extension methods like Kotlin and C #, including interfaces could have a much more interesting impact.

Unfortunately, this also means that existing libraries must use bridges to convert between Java 9 Flow and Reactive-Streams and / or redefine the entire library with the Java 9 Flow API - cut someone without Java 9 (i.e. . Android).

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

+8
source

The purpose of the stream interface is to provide a "standard for asynchronous non-blocking backpressure stream processing." There are already many solutions that achieve this (for example, Rx), but by introducing a common interface, it maximizes interoperability.

back pressure is the key point when back pressure occurs, if the manufacturer gives a call back, the consumer can call this callback at a speed exceeding the speed that the manufacturer can handle.

It is easy to achieve a backpressure LOCK by running them in the same thread so that the consumer and the manufacturer block each other.

This flow interface will allow us to achieve NON BLOCKING backpressure.

The details of this are explained in more detail in this link (as well as information on how to use the interface): https://aboullaite.me/java-9-new-features-reactive-streams/

+2
source

Source: https://habr.com/ru/post/1272063/


All Articles