在不断变化的过程中,只要有oom,整个过程就会陷入困境,直到我们手动杀死它。我创建了一个例子来模拟它。请参考以下代码:
@Test
public void test_Flux() {
Flux.range(1, 30)
.parallel(6)
.runOn(Schedulers.fromExecutor(Executors.newFixedThreadPool(6)))
.doOnNext(this::writeValues)
.sequential()
.blockLast();
}
private void writeValues(int val) {
if (val == 10) {
throw new OutOfMemoryError("failed here");
// throw new RuntimeException("failed here");
}
System.out.println("the thread name is :" + Thread.currentThread().getName() + " val is :" + val);
sleep(3);
}
private void sleep(int i) {
try {
Thread.sleep(i * 1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
我们能在这里撞车而不是被卡住吗?
暂无答案!
目前还没有任何答案,快来回答吧!