2012-12-20 88 views
0
public class TomcatStopListener implements ServletContextListener { 


    public void contextDestroyed(ServletContextEvent arg0) { 

    // How to get reference of already running Quartz Scheduler here?? 


     } 

} 

在停止tomcat服務器,我想停止石英調度程序以避免錯誤,我知道scheduler.shutdown();但是我怎樣才能在這裏得到調度器的參考?如何在ServletContextListener中獲得對Quartz Scheduler的引用? (struts 2)

+0

最簡單的方法是將調度例如在servlet上下文。你是怎麼開始的?什麼時候? –

回答

0

如果你已經使用QuartzInitializerServlet初始化你的石英,那麼你可以這樣做

StdSchedulerFactory factory = (StdSchedulerFactory) ctx 
      .getAttribute(QuartzFactoryServlet.QUARTZ_FACTORY_KEY); 

contextDestroyed方法,其中ctx是你的ServletContext裏。 StdSchedulerFactory實例存儲在ServletContext中。

欲瞭解更多信息,請參閱Quartz Initializer Servlet

+0

謝謝.. 仍然我不得不在QuartzSchedulerListener類中添加QUARTZ_FACTORY_KEY的聲明和setAttribute以使其工作: - public static final String QUARTZ_FACTORY_KEY =「org.quartz.impl.StdSchedulerFactory.KEY」; ServletContextEvent.getServletContext()。setAttribute(QUARTZ_FACTORY_KEY,factory); –