Can any one explain why this code never ends (always throws TimeoutException), 3.0.7 and 3.1.0.M3 all the same ? I thought remaining 4 threads will do their work piece-by-piece.
private static class Holder {
private final int group, idx;
Holder(int group, int idx) {
this.group = group;
this.idx = idx;
}
}
private static final Logger log = LoggerFactory.getLogger(RxTest2.class);
@Test
public void test1() throws Exception {
final Scheduler scheduler = Schedulers.parallel();
final AtomicInteger c = new AtomicInteger();
Flux.range(0, 8).flatMap(gi -> Flux.range(0, 30).map(i -> new Holder(gi, i)))
.groupBy(h -> h.group)
.parallel()
.runOn(scheduler)
.flatMap(chunk -> {
log.debug("chunk {}", chunk.key());
chunk
.parallel()
.runOn(scheduler)
.flatMap(h -> {
log.debug("{} - {}", h.group, h.idx);
c.incrementAndGet();
return Mono.just(true);
})
.sequential()
.blockLast();
return Mono.just(true);
})
.sequential()
.timeout(Duration.ofSeconds(2))
.doOnTerminate(() -> log.debug("count: {}", c.get()))
.blockLast();
}
if I split it to separate schedulers (Schedulers.newParallel("p1", 8), Schedulers.newParallel("p2")) - all is OK
Is there some special rule for counting number of threads for scheduler?
您似乎在Schedulers.parallel()上运行了多个并行计算,并且它们完全饱和了调度程序,因此没有线程可用于处理.flatMap(chunk ->
。这里有线程饥饿的情况。只需删除内部chunk.parallel
,不需要这样做,因为计算已经是并行的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.