2011-09-28 82 views
7

Tôi đang sử dụng Quartz để chạy một công việc mỗi giờ. Servlet đang chạy trên Tomcat và tôi đang sử dụng ServletConextListener để lắng nghe khi ngữ cảnh bị phá hủy.Quartz: Rò rỉ bộ nhớ?

Khi tôi đóng cửa tomcat, tôi nhận được thông báo:

"dường như đã bắt đầu một chủ đề mang tên [MyScheduler_Worker-1] nhưng đã thất bại trong việc ngăn chặn nó".

Nhưng sau đó tôi thấy thông báo này:

"[DEBUG] Tháng Chín 28 11: 45:. 26,671 AM MyScheduler_Worker-1 [org.quartz.simpl.SimpleThreadPool]

WorkerThread tắt"

Vì vậy, có an toàn để giả định rằng không có rò rỉ bộ nhớ nào do chuỗi này không?

Sau đây là cách đăng nhập của tôi trông:

{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 được cho là không để cho đủ thời gian để thạch anh để tắt đề. Nhưng tôi chưa thể xác minh điều này. – Codo

Trả lời

0

Bạn có thể giả định không có bộ nhớ bị rò rỉ bởi vì bạn thấy thông báo chủ đề tắt máy. Tuy nhiên, nó có thể đến hơn cảnh báo bằng cách xóa các chủ đề trước khi tắt.

The shutdown-hook plugin catches the event of the JVM terminating, and calls shutdown on the scheduler. 

chi tiết: - http://quartz-scheduler.org/documentation/quartz-2.x/configuration/ConfigPlugins

4

Tôi biết đây là một chủ đề cũ nhưng trong trường hợp những người khác đang tìm kiếm nó.

Chúng tôi sử dụng để nhận cảnh báo về chủ đề mọi lúc cho đến khi chúng tôi thêm mã để tắt Trình lập lịch biểu thạch anh trong phương thức ServletContextListener.shutDown() của chúng tôi.

Để tắt 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; 
       } 
      }