Home > Java > javaTutorial > body text

What is the core interface of Reactive Streams in Java 9?

WBOY
Release: 2023-08-27 20:37:02
forward
1265 people have browsed it

Java 9中的Reactive Streams的核心接口是什么?

Java 9 introduces responsive flow under the java.util.concurrent.Flow package to support interoperable Publish-Subscribe Framework. It handles asynchronous data streams across asynchronous boundaries (passing elements to another thread or thread pool), and the receiver is not forced to buffer any amount of data, so buffer overflows cannot occur.

Flow API contains four interrelated core interfaces: Publisher, Subscriber, Subscribe and processor.

Syntax

<strong>@FunctionalInterface
</strong>public static interface <strong>Publisher<T></strong> {
   public void <strong>subscribe</strong>(<strong>Subscriber</strong><? super T><!--? super T--> subscriber)
}
public static interface <strong>Subscriber<T></strong> {
   public void <strong>onSubscribe</strong>(Subscription subscription);
   public void <strong>onNext</strong>(T item);
   public void <strong>onError</strong>(Throwable throwable);
   public void <strong>onComplete</strong>();
}
public static interface <strong>Subscription </strong>{
   public void <strong>request</strong>(long n);
   public void <strong>cancel</strong>();
}
public static interface <strong>Processor<T, R> </strong>extends <strong>Subscriber<T></strong>, <strong>Publisher<R></strong> {
}
Copy after login

These four interfaces: Flow.Publisher, Flow.Processor, Flow.Subscriber and Flow. Subscriptions related to reactive streams specifications. Publisher interface has subscribe() method, subscription has cancel() and request() methods, Subscribers have onSubscribe(), onNext(), onError() and >onComplete() methods . Processorinterface implements all methods of Flow. Publisher and Flow.Subscriber interfaces.

The above is the detailed content of What is the core interface of Reactive Streams in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template