2009-06-17 84 views
2

我正在使用Spring Quartz集成,每當我嘗試關閉Tomcat時,Quartz進程都無法關閉。這是堆棧軌跡:與Quartz&Spring的空指針異常

Exception in thread "org.springframework.scheduling.quartz.SchedulerFactoryBean#0_QuartzSchedulerThread" 
     java.lang.NullPointerException 
    at org.apache.commons.logging.LogFactory.getCachedFactory(LogFactory.java:979) 
    at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:435) 
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685) 
    at org.quartz.core.QuartzSchedulerThread.getLog(QuartzSchedulerThread.java:475) 
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:404) 

有沒有人看起來這樣?

回答

7

如果您看看SchedulerFactoryBean,它有一個名爲waitForJobsToCompleteOnShutdown的屬性。當Spring ApplicationContext收到關閉請求時,它會通知Quartz Scheduler關閉,並有條件地告訴它在關閉之前等待所有作業完成。

但是,如果Spring被告知正在處理的Tomcat上下文,Spring只能處理請求關閉(並告訴Quartz)關閉的請求。你如何在Tomcat中使用Spring?你有一個ServletContextListener註冊來電applicationContext.destroy()

實際的NPE可能是由於Tomcat在關機時將應用程序運行的classLoader中的所有static引用設置爲null引起的。這樣做有助於防止在Tomcat回收/重新啓動期間發生任何內存泄漏。但是,如果你的線程仍然在Tomcat容器中運行(因爲它們沒有正確關閉,比如你的Quartz線程),那麼當線程中的代碼(例如你的代碼試圖訪問它的記錄器的石英線程 - 很可能保留爲static)嘗試訪問已被清除的任何靜態引用。

+0

我在哪裏可以找到關於這方面的文檔? – 2012-09-11 20:24:04

1

你有WAR內打包的commons-logging副本嗎?如果是這樣,作爲Tomcat一部分的副本與WAR中的副本之間可能存在奇怪的交互。嘗試刪除WAR副本,看看是否有幫助。

+0

這確實解決了我最初的NullPointerException異常問題 - 但它被一個ClassNotFound異常取代了...所以我投票給你,但是Matt的回答實際上解決了問題的其餘部分,所以我選擇了它。謝謝! – stevedbrown 2009-06-17 21:53:50