Issue
In a spring boot app (2.1.4-RELEASE) when using the following configuration of a TaskExecutor
@Primary
@Qualifier("threadPoolTaskExecutor")
@Bean
public TaskExecutor threadPoolTaskExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(100);
executor.setQueueCapacity(50);
executor.setThreadNamePrefix("Foo-");
executor.initialize();
return new DelegatingSecurityContextAsyncTaskExecutor(executor);
}
when shutting down tomcat (9.0.19) I get the following warning.
02-May-2019 10:34:07.384 WARNUNG [main] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [myapp#bar] appears to have started a thread named [Foo-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
[email protected]/jdk.internal.misc.Unsafe.park(Native Method)
[email protected]/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
[email protected]/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2081)
[email protected]/java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:433)
[email protected]/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054)
[email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114)
[email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[email protected]/java.lang.Thread.run(Thread.java:834)
The warning disappears when the DelegatingSecurityContextAsyncTaskExecutor is removed:
@Primary
@Qualifier("threadPoolTaskExecutor")
@Bean
public TaskExecutor threadPoolTaskExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(100);
executor.setQueueCapacity(50);
executor.setThreadNamePrefix("Foo-");
executor.initialize();
return executor;
}
What is the cause? How can that be solved?
Update: I excuse (please don't stone me) but I completely forgot that it is a spring boot app which is being deployed as an exploded war in the tomcat. I now tried as well tomcat version 9.0.17 which is used by Spring 2.1.4.RELEASE but same problem. When starting the spring boot by itself then the problem does not appear.
Update2: Opened a bug
Solution
Was answered by Rob Winch here.
Answered By - Kavau
Answer Checked By - Terry (JavaFixing Volunteer)