我有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;
}
答案 0 :(得分:1)