Bạn có chắc chắn muốn xóa bài viết này không ?
Bạn có chắc chắn muốn xóa bình luận này không ?
Java 9 FLow SubmissionPublisher – A Concrete Publisher
https://grokonez.com/java/java-9/java-9-flow-submissionpublisher-concrete-publisher
Java 9 FLow SubmissionPublisher – A Concrete Publisher
JDK 9 provides a concrete Publisher named SubmissionPublisher that acts as a compliant Reactive Streams Publisher relying on drop handling and/or blocking for flow control. In this tutorial, we're gonna take a look at SubmissionPublisher and an example that generates items for Subscribers.
Related Articles:
- Java 9 Flow API – Reactive Streams
- Java 9 Flow API example – Publisher and Subscriber
- Java 9 Flow API example – Processor
I. Technologies
- Java 9
- Eclipse with Java 9 Support for Oxygen (4.7)
II. Overview
1. SubmissionPublisher
SubmissionPublisher is an implementation of Java 9Flow.Publisher
that asynchronously issues items to its subscribers until closing.
Depending on usage, we can indicate the Executor
for SubmissionPublisher in its constructor methods:
- If we wanna submitting items in separate threads, and can estimate number of subscribers, consider using
Executors.newFixedThreadPool(int)
and constructor method:SubmissionPublisher(Executor executor, int maxBufferCapacity); // maxBufferCapacity: the maximum capacity for each subscriber's buffer.
- Otherwise, just call the default constructor (no input parameter) that will use
ForkJoinPool.commonPool()
.
If a Subscriber has only one action that requests and processes all items, we can consider using consume(Consumer)
method (which returns a CompletableFuture
object) like this:
publisher.consume((data) -> process(data));
https://grokonez.com/java/java-9/java-9-flow-submissionpublisher-concrete-publisher
Java 9 FLow SubmissionPublisher – A Concrete Publisher




