How to stop all running threads in ThreadPoolTaskExecutor?
I am adding new streams like this using ThreadPoolTaskExecutor
:
threadPoolTaskExecutor.execute(new Runnable() {
@Override
public void run() {
while(true){
doSomething();
}
Thread.sleep(1000);
}
});
All active threads don't stop when I terminate this executor:
threadPoolTaskExecutor.shutdown();
Is there an option to stop these active threads with ThreadPoolTaskExecutor
?
+3
source to share
1 answer
You must set setWaitForTasksToCompleteOnShutdown (false) on creation ThreadPoolTaskExecutor
.
By default, this is used false
, immediately disconnects, interrupting current tasks and freeing the queue.
+2
source to share