Starting from Java 9, we can create Reactive Streams by introducing four core interfaces: Publisher , Subscriber, Subscription, Processor and a concrete class: the SubmissionPublisher interface that implements Publisher. Each interface plays a different role, corresponding to the principles of ResponsivenessFlow. We can publish the provided items to each subscriber using the submit() method of the SubmissionPublisher class.
Syntax
<strong>public class SubmissionPublisher<T> extends Object implements Flow.Publisher<T>, AutoCloseable</strong>
In the following example, we can implement SubmissionPublisher Class
Example
import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.Flow.Subscription; import java.util.concurrent.SubmissionPublisher; class MySubscriber<T> implements <strong>Subscriber<T></strong> { private <strong>Subscription </strong>subscription; private String name; public MySubscriber(String name) { this.name = name; } <strong>@Override</strong> public void <strong>onComplete()</strong> { System.out.println(name + ": onComplete"); } <strong>@Override</strong> public void <strong>onError</strong>(Throwable t) { System.out.println(name + ": onError"); t.printStackTrace(); } <strong> @Override</strong> public void <strong>onNext</strong>(T msg) { System.out.println(name + ": " + msg.toString() + " received in onNext"); subscription.<strong>request</strong>(1); } <strong>@Override</strong> public void <strong>onSubscribe</strong>(Subscription subscription) { System.out.println(name + ": onSubscribe"); this.subscription = subscription; subscription.<strong>request</strong>(1); } } <strong>// Main class</strong> public class FlowTest { public static void main(String args[]) { <strong>SubmissionPublisher<String></strong> publisher = new <strong>SubmissionPublisher</strong><>(); MySubscriber<String> subscriber = new MySubscriber<>("Mine"); MySubscriber<String> subscriberYours = new MySubscriber<>("Yours"); MySubscriber<String> subscriberHis = new MySubscriber<>("His"); MySubscriber<String> subscriberHers = new MySubscriber<>("Her"); publisher.<strong>subscribe</strong>(subscriber); publisher.<strong>subscribe</strong>(subscriberYours); publisher.<strong>subscribe</strong>(subscriberHis); publisher.<strong>subscribe</strong>(subscriberHers); publisher.<strong>submit</strong>("One"); publisher.<strong>submit</strong>("Two"); publisher.<strong>submit</strong>("Three"); publisher.<strong>submit</strong>("Four"); publisher.<strong>submit</strong>("Five"); try { Thread.sleep(1000); } catch(InterruptedException e) { e.printStackTrace(); } publisher.close(); } }
output
<strong>Yours: onSubscribe His: onSubscribe Mine: onSubscribe His: One received in onNext Yours: One received in onNext Mine: One received in onNext Yours: Two received in onNext His: Two received in onNext Yours: Three received in onNext Mine: Two received in onNext Yours: Four received in onNext His: Three received in onNext Yours: Five received in onNext Mine: Three received in onNext Her: onSubscribe His: Four received in onNext Her: One received in onNext Mine: Four received in onNext Her: Two received in onNext His: Five received in onNext Her: Three received in onNext Mine: Five received in onNext Her: Four received in onNext Her: Five received in onNext Yours: onComplete His: onComplete Mine: onComplete Her: onComplete</strong>
The above is the detailed content of In Java 9, how do we implement SubmissionPublisher class?. For more information, please follow other related articles on the PHP Chinese website!

This article analyzes the top four JavaScript frameworks (React, Angular, Vue, Svelte) in 2025, comparing their performance, scalability, and future prospects. While all remain dominant due to strong communities and ecosystems, their relative popul

This article addresses the CVE-2022-1471 vulnerability in SnakeYAML, a critical flaw allowing remote code execution. It details how upgrading Spring Boot applications to SnakeYAML 1.33 or later mitigates this risk, emphasizing that dependency updat

Node.js 20 significantly enhances performance via V8 engine improvements, notably faster garbage collection and I/O. New features include better WebAssembly support and refined debugging tools, boosting developer productivity and application speed.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

This article explores methods for sharing data between Cucumber steps, comparing scenario context, global variables, argument passing, and data structures. It emphasizes best practices for maintainability, including concise context use, descriptive

This article explores integrating functional programming into Java using lambda expressions, Streams API, method references, and Optional. It highlights benefits like improved code readability and maintainability through conciseness and immutability

Iceberg, an open table format for large analytical datasets, improves data lake performance and scalability. It addresses limitations of Parquet/ORC through internal metadata management, enabling efficient schema evolution, time travel, concurrent w


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
