【发布时间】:2017-06-22 17:03:59
【问题描述】:
假设我有如下代码:
Future<Object> executeBy(ExecutorService executor) {
return executor.submit(() -> {
throw new IllegalStateException();
});
}
使用ForkJoinPool#commonPool 时没有问题,但是当我使用并行性ForkJoinPool 时,它会使IllegalStateException 翻倍。例如:
executeBy(new ForkJoinPool(1)).get();
// ^--- double the IllegalStateException
Q1:为什么ForkJoinPool 是Exception 的两倍出现在Callable 中?
Q2:如何避免这种奇怪的行为?
【问题讨论】:
标签: java exception java-8 fork-join