ParallelFlux vs flatMap() for a Blocking I/O task

后端 未结 1 1636
北荒
北荒 2020-12-28 08:25

I have a Project Reactor chain which includes a blocking task (a network call, we need to wait for response). I\'d like to run multiple blocking tasks concurrently.

相关标签:
1条回答
  • 2020-12-28 08:56

    parallel is tailored for parallelization of tasks for performance purposes, and dispatching of work between "rails" or "groups", each of which get their own execution context from the Scheduler you pass to runOn. In short, it will put all your CPU cores to work if you do CPU intensive work. But you're doing I/O bound work...

    So in your case, flatMap is a better candidate. That use of flatMap for parallelization is more about orchestration.

    These are pretty much the 2 alternatives, if you don't count the slightly different flavor of flatMap that flatMapSequential is (concatMap doesn't really allow for parallelization).

    0 讨论(0)
提交回复
热议问题