1

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;
        }

1 Answer 1

1

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.