1
我有一個簡單的ThreadPoolExecutor用例。我想確保在線程執行期間是否有任何類型的運行時異常,線程是否會返回到池中。如何驗證?如果將來的任務拋出異常,線程是否返回到執行程序服務的線程池?
ExecutorService pool = Executors.newFixedThreadPool(30);
pool.submit(new MyThread())
boolean jobExecutionStatus =true
try{
for (Future<Boolean> future : futureArrayList){
if (jobExecutionStatus){
jobExecutionStatus = future.get();
}
else{
break;
}
}
}
catch (InterruptedException | ExecutionException e){
jobExecutionStatus = false;
}
非常感謝您的迅速回復。 –