2011-09-28 47 views
7

我正在使用Quartz來每小時運行一項工作。 Servlet在Tomcat上運行,我正在使用ServletConextListener來偵聽上下文何時被銷燬。石英:內存泄漏?

當我關閉Tomcat,我得到的消息:

「似乎已經開始了一個名爲[MyScheduler_Worker-1]線程,但未能阻止它」。

但後來我看到這條消息:

「[DEBUG] 11年9月28日:45:26.671 AM MyScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]

的WorkerThread被關閉。」

因此,假設這個線程沒有內存泄漏是安全的嗎?

這裏是我的日誌的外觀:

{SEVERE: The web application [/*************] appears to have started a thread 

named [MyScheduler_Worker-1] but has failed to stop it. This is very likely to c 

reate a memory leak. 

Sep 28, 2011 11:45:26 AM org.apache.catalina.loader.WebappClassLoader clearRefer 

encesThreads 

SEVERE: The web application [/*************] appears to have started a thread 

named [MyScheduler_Worker-2] but has failed to stop it. This is very likely to c 

reate a memory leak. 

Sep 28, 2011 11:45:26 AM org.apache.catalina.loader.WebappClassLoader clearRefer 

encesThreads 

SEVERE: The web application [/*************] appears to have started a thread 

named [MyScheduler_Worker-3] but has failed to stop it. This is very likely to c 

reate a memory leak. 

[DEBUG] 28 Sep 11:45:26.671 AM MyScheduler_Worker-2 [org.quartz.simpl.SimpleThre 

adPool] 

WorkerThread is shut down. 



[DEBUG] 28 Sep 11:45:26.671 AM MyScheduler_Worker-1 [org.quartz.simpl.SimpleThre 

adPool] 

WorkerThread is shut down. 



[DEBUG] 28 Sep 11:45:26.671 AM MyScheduler_Worker-3 [org.quartz.simpl.SimpleThre 

adPool] 

WorkerThread is shut down. 
+0

的Tomcat是說沒有給足夠的時間,以石英來關閉線程。但我還沒有能夠驗證這一點。 – Codo

回答

4

我知道這是一個古老的線程,但萬一別人都在尋找它。

我們一直使用線程的警告,直到我們在ServletContextListener.shutDown()方法中添加了關閉Quartz Scheduler的代碼。

要關閉計劃:

  quartzScheduler.shutdown(); 

      int ct = 0; 

      // Try waiting for the scheduler to shutdown. Only wait 30 seconds. 
      while(ct < 30) { 
       ct++; 
       // Sleep for a second so the quartz worker threads die. This 
       // suppresses a warning from Tomcat during shutdown. 
       Thread.sleep(1000); 
       if (quartzScheduler.isShutdown()) { 
        break; 
       } 
      }