我正在使用一个实现ServletContextListener的servlet来启动石英调度器实例@starup。在contextDestroyed()方法中,调度程序实例被停止。
@Override
public void contextDestroyed(ServletContextEvent sce) {
try {
Scheduler scheduler = QuartzSchedulerUtil.getCurrentScheduler();
scheduler.shutdown(true);
// Sleep for a bit so that we don't get any errors
Thread.sleep(1000);
Driver mySqlDriver = DriverManager.getDriver(hibernateConnectionUrl);
DriverManager.deregisterDriver(mySqlDriver);
} catch (SchedulerException ex) {
Logger.getLogger(QuartzServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(QuartzServlet.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(QuartzServlet.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("THE QUARTZ APP STOPPED");
}
但是当部署应用程序时,我会收到内存泄漏警告,指定woker线程没有停止。
Jul 10, 2012 3:46:12 PM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads SEVERE: The web application [/latest-raisin]
appears to have started a thread named [Timer-0] but has failed to
stop it. This is very likely to create a memory leak.
Jul 10, 2012 3:46:12 PM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads SEVERE: The web application [/latest-raisin]
appears to have started a thread named
[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but
has failed to stop it. This is very likely to create a memory leak.
Jul 10, 2012 3:46:12 PM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads SEVERE: The web application [/latest-raisin]
appears to have started a thread named
[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but
has failed to stop it. This is very likely to create a memory leak.
Jul 10, 2012 3:46:12 PM org.apache.catalina.loader.WebappClassLoader
clearReferencesThreads SEVERE: The web application [/latest-raisin]
appears to have started a thread named
[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but
has failed to stop it. This is very likely to create a memory leak.
我尝试了帖子中提到的解决方案——http://forums.terracotta.org/forums/posts/list/15/4341.page但当应用程序未部署时,仍会收到严重内存泄漏警告。
您可以在org.quartz.scheduler.interruptJobsOnShutdown
中设置属性,以便在想要关闭时,如果作业仍在执行中,则中断作业。