Reputation: 3898
I have simple use case of ThreadPoolExecutor. I want to ensure during the thread execution if there is any kind of run time exception, Will threads be returned back to the pool or not. How to verify ?
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;
}
Upvotes: 1
Views: 172
Reputation: 26926
No, if an Exception
is thrown a new Thread
will be created (only if necessary).
From javadoc:
If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks.
Upvotes: 1