简体   繁体   中英

How to stop all running threads in ThreadPoolTaskExecutor?

I am add new threads like this using ThreadPoolTaskExecutor :

threadPoolTaskExecutor.execute(new Runnable() {

    @Override
    public void run() {
        while(true){
            doSomething();
        }

        Thread.sleep(1000); 
    }

});

All active threads are not stopped, when I shutdown this executor:

threadPoolTaskExecutor.shutdown();

Is there option how to stop this active threads using ThreadPoolTaskExecutor ?

You should set setWaitForTasksToCompleteOnShutdown(false) when create ThreadPoolTaskExecutor .

Default is false , shutting down immediately through interrupting ongoing tasks and clearing the queue.

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