Scheduler

Scheduler is an interface that has two central methods: Scheduler.schedule and Scheduler.createWorker. The first method makes it possible to schedule a Runnable task, whereas the second one provides us with a dedicated instance of the Worker interface, which can schedule Runnable tasks in the same way. The central difference between the Scheduler interface and the Worker interface is that the Scheduler interface represents a pool of workers, whereas Worker is a dedicated abstraction over the Thread or a resource. By default, Reactor provides three central Scheduler interface implementations,  which are listed as follows:

  • SingleScheduler allows the scheduling of all possible tasks for one dedicated worker. It is time-capable, so it can schedule periodical events with a delay. This scheduler may be referenced with the Scheduler.single() call.
  • ParallelScheduler works on a fixed size pool of workers (by default, the size is bound to the number of CPU cores). Fits well for CPU bound tasks. Also, by default, handles time-related scheduled events, for example, Flux.interval(Duration.ofSeconds(1)). This scheduler may be referenced with the Scheduler.parallel() call.
  • ElasticScheduler dynamically creates workers and caches thread pools. The maximum number of created thread pools is unbounded, so this scheduler fits well when we need a scheduler for IO-intensive operations. This scheduler may be referenced with the Scheduler.elastic() call.

Also, we can implement our own Scheduler with our desired characteristics. Chapter 10And, Finally, Release It! gives an example of how to create a Scheduler for Reactor with extensive monitoring capabilities.

To learn more about Threading and Schedulers please see the following part of Project Reactor documentation [http://projectreactor.io/docs/core/release/reference/#schedulers]

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.103.96