In this example we are going to demonstrate how does the java.util.concurrent.Flow
API work in general. For that purpose we are going to create an implementation of the java.util.concurrent.Flow.Subscriber
interface (com.project.DefaultSubscriber
) and register a concrete subscriber to a given java.util.concurrent.Flow.Publisher
instance. The flow publisher is an instance of the java.util.concurrent.SubmissionPublisher
class provided by JDK 9 that implements the java.util.concurrent.Flow.Publisher
API.
In the source folder there is a PrimeNumberSubscriber
project that provides a stub implementation of the subscriber and demo for the publisher.
Add implementation of the onNext() and onSubscribe() methods accordingly. The onNext() method should check if the passed number is prime or not and print the result on the standard output. Then create an instance of the com.project.DefaultSubscriber
class and register it to the publisher created in the com.project.Main
class.
Use the compile.sh
script to compile the project:
$ ./compile.sh
Run the compiled com.project.Main
class with the run.sh
script:
$ ./run.sh