2011-09-28 8 views
7

Sto usando Quartz per eseguire un lavoro ogni ora. Il servlet è in esecuzione su Tomcat e sto utilizzando ServletConextListener per ascoltare quando il contesto viene distrutto.Quarzo: perdita di memoria?

quando chiudo Tomcat, ottengo il messaggio:

"sembra aver iniziato una discussione chiamato [MyScheduler_Worker-1], ma non è riuscito a fermarlo".

Ma più tardi vedo questo messaggio:

"[DEBUG] 28 Settembre 11: 45: 26,671 AM MyScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]

WorkerThread viene arrestato."

Quindi è lecito ritenere che non ci siano perdite di memoria a causa di questo thread?

Ecco come il mio registro appare:

{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 si dice di non dare abbastanza tempo per quarzo per l'arresto dei fili. Ma non sono ancora riuscito a verificarlo. – Codo

risposta

4

So che questo è un vecchio thread, ma nel caso in cui gli altri sono alla ricerca di esso.

Usiamo per ricevere gli avvertimenti dei thread tutto il tempo fino a quando non abbiamo aggiunto il codice per arrestare il programma di pianificazione Quartz nel nostro metodo ServletContextListener.shutDown().

Per spegnere lo 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; 
       } 
      }