Along with non-trivial operators for managing threads on which we want to process some part of the execution flow, Reactor offers a familiar technique for work paralleling. For that purpose, Reactor has an operator called .parallel, which allows the splitting of the flow on to the parallel substreams and the balancing of elements between them. The following is an example of this operator in use:
Flux.range(0, 10000)
.parallel()
.runOn(Schedulers.parallel())
.map()
.filter()
.subscribe()
As we can see from the preceding example, .parallel() is a part of the Flux API. One thing that we have noticed here is that, by applying the parallel operator, we start operating on a different type of Flux, which is called ParallelFlux. ParallelFlux is an abstraction over a group of Fluxes, between which the elements in the source Flux are balanced. Then, by applying the runOn operator, we can apply publishOn to internal Fluxes and distribute work related to elements being processed between different workers.