2012-07-10 31 views
2

我正在使用實現ServletContextListener的servlet來啓動quartz scheduler實例@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 但仍然得到嚴重的內存泄漏的警告時,器件的應用被卸載。

+0

你確定'scheduler.shutdown(true);'夠了嗎?也許不是石英問題,而是c3p0問題?在那裏也創建了一個計時器我也想:http://grepcode.com/file/repo1.maven.org/maven2/c3p0/c3p0/0.9.1/com/mchange/v2/async/ThreadPoolAsynchronousRunner.java – 2012-10-15 10:57:52

回答

0

您可以設置org.quartz.scheduler.interruptJobsOnShutdown中的屬性來中斷作業,如果它們在您要關閉時仍在執行中。