CKTIS / Java
util.concurrent.SubmissionPublisher: practical reference
util.concurrent.SubmissionPublisher: practical reference: SubmissionPublisher<T> asynchronously delivers non-null items to current Flow.Subscribers through an independent buffer per subscriber.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.util.concurrent.SubmissionPublisherSubmissionPublisher asynchronously delivers non-null items to current Flow.Subscribers through an independent buffer per subscriber.
Use it as a simple reactive-streams publisher with an explicit Executor, capacity, and backpressure or drop policy.
submit may block uninterruptibly for buffer space, while offer may drop an item per subscriber and invoke onDrop.
Lag and demand values are estimates, not synchronization controls; close signals onComplete, closeExceptionally signals onError, and null is forbidden.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
try (var publisher = new java.util.concurrent.SubmissionPublisher<Integer>(Runnable::run, 8)) {
publisher.subscribe(new java.util.concurrent.Flow.Subscriber<>() {
public void onSubscribe(java.util.concurrent.Flow.Subscription subscription) { subscription.request(1); }
public void onNext(Integer item) { System.out.println(item); }
public void onError(Throwable error) { throw new RuntimeException(error); }
public void onComplete() {}
});
publisher.submit(7);
}
}
}
Result
7
The example exercises the documented element in a small deterministic program and compares exact standard output.