The ExecutorService scheduler

The Schedulers.fromExecutor enables us to build a scheduler over the Java ExecutorService. The scheduler does not own thread generation, but instead, it is controlled by the underlying ExecutorService. The scheduler should not be favored over other schedulers, as the life cycle of the ExecutorService must be managed by the developer. Consider the following code:

 @Test    public void testExecutorScheduler() throws Exception{        // Removed for Brevity        ExecutorService executor = Executors.newSingleThreadExecutor();        fibonacciGenerator                .filter(x -> {                    print("Executing Filter");                    return x < 100;                }).delayElements(Duration.ZERO,Schedulers.fromExecutor(executor))                 .doOnNext(x -> print("Next value is  "+ x)) .doFinally(x -> print("Closing ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.