假設我有一個像下面的代碼:爲什麼並行性ForkJoinPool會使我的異常加倍?
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:如何避免這種奇怪的行爲?
[相關](HTTPS://計算器
該功能可以很容易地通過投擲不具有匹配的公共構造在F/J可以使用,像本整齊內部類的異常類型禁用。 com/q/38994907/2711488) – Holger