I have a tomcat instance with a Spring web application.
It starts a scheduled job with this code:
checkExecutor=Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread tr=new Thread(r, "checkTimer");
tr.setDaemon(true);
return tr;
}
});
Please consider its thread is flagged as daemon.
When I stop tomcat, this error is thrown:
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [checkTimer] 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.parkNanos(Unknown Source)
[email protected]/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
[email protected]/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
[email protected]/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
[email protected]/java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
[email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[email protected]/java.lang.Thread.run(Unknown Source)
Why it is complaining that my thread has not been stopped if it is a “daemon” thread? Is it not enought to avoid the explicit call to shutdown()
?