简体   繁体   中英

Is thread returned to threadpool of executor service if future task throws exception?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM