top of page
Search

Reactive Programming Thread Schedulers

  • maheshkamineni35
  • Apr 16, 2024
  • 1 min read

Reactive Streams provide a standard for asynchronous stream processing. We achieve asynchronous/non-blocking behavior by scheduling tasks on worker threads. Creating and managing threads ourselves is not an easy task. Project Reactor provides convenient factory methods to use workers threads via Schedulers class. This is what we would be discussing in this post.


Here the map function simply returns the received value. We just wanted to do some logging to see the thread name which is doing the map operation. In the below runnable implementation, we simply subscribe to the above flux! Do note that in the reactive programming world, nothing happens until you subscribe!


//create a runnable with flux subscription
Runnable r = () -> flux.subscribe(s -> {
    System.out.println("Received " + s + " via " + Thread.currentThread().getName());
});

 
 
 

Recent Posts

See All

Comments


bottom of page