I am using a timer task in my web app and in onContextDestroyed handler, I am using the following code to make everything null:
System.out.println("contextDestroyed - fileWatcherTask:"+fileWatcherTask);
System.out.println("contextDestroyed - mytimer:"+mytimer);
fileWatcherTask.cancel();
mytimer.cancel();
System.gc();
if (fileWatcherTask != null) {
System.out.println("fileWatcherTask is not null");
fileWatcherTask=null;
}
if (mytimer!=null)
{
System.out.println("mytimer is not null");
mytimer=null;
}
System.out.println("contextDestroyed - logTimerTask After invoking cancel mytimer: "+mytimer);
System.out.println("contextDestroyed - logTimerTask After invoking cancel fileWatcherTask: "+fileWatcherTask);
However, sometimes it is printing as null and sometimes it’s not. Can anyone tell me what the problem is? And if it is not null the I get the following Catalina log output:
SEVERE: The web application [/LoggingMonitor] appears to have started a thread named [Timer-1] but has failed to stop it. This is very likely to create a memory leak.