How can I perform flatMap using multiple threads in Reactor?

*爱你&永不变心* 提交于 2019-12-11 01:53:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!