问题
I have tried running a flatMap
on a Flux
range
followed by subscribeOn
and it seems all operations run on the same thread. Is this normal?
Flux.range(0, 1000000).log().flatMap{ it + 1 }.subscribeOn(Schedulers.parallel()).subscribe()
回答1:
You can create a ParallelFlux as follows:
Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe()
^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^
来源:https://stackoverflow.com/questions/53409567/how-can-i-perform-flatmap-using-multiple-threads-in-reactor