通过查看 API,我的理解是使用 Schedulers.boundedElastic() 或 Schedulers.newBoundedElastic(3, 10, "MyThreadGroup"); 等变体;或 Schedulers.fromExecutor(executor) 允许在多个线程中处理 IO 操作。
但是使用以下示例代码进行的模拟似乎表明单个线程/同一线程正在 flatMap 中执行工作
Flux.range(0, 100)
.flatMap(i -> {
try {
// IO operation
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Mapping for " + i + " is done by thread " + Thread.currentThread().getName());
return Flux.just(i);
})
.subscribeOn(Schedulers.boundedElastic())
.subscribe();
Thread.sleep(10000); // main thread
//This yields the following
Mapping for 0 is done by thread boundedElastic-1
Mapping for 1 is done by thread boundedElastic-1
Mapping for 2 is …Run Code Online (Sandbox Code Playgroud)