Managing task executions using Schedulers
All Mono<T>
and Flux<T>
Streams use the main thread for executing all its processors, which in some circumstances, can create starvation in some applications that are waiting for the main thread to be released. Eventually, exceptions from both publisher and subscriber can be thrown due to the starvation generated by the thread problems. This recipe will discuss creating thread workers that will lighten up the load of the main thread.
Getting ready
Open project ch08
again and add some services that will illustrate the different ways to create schedulers or thread executors.
How to do it...
To apply schedulers on our Stream operators, let us perform the following steps:
- Create a service class
EmployeeScheduledStreamservice
that contains the following methods that will make use of the custom dispatcher and thread executor on the main thread:
public interface EmployeeScheduledStreamservice { public Flux<Employee> createPublisherThread...