Java tutorial
/* * Distributable under LGPL v3 license. * See terms of license at https://github.com/Yunfeng/schotel/blob/master/LICENSE */ package cn.buk.qms.listener; import org.springframework.web.context.WebApplicationContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; /** * User: yfdai * Date: 14-9-1 * Time: ?3:54 */ public class QuartzContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent servletContextEvent) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void contextDestroyed(ServletContextEvent arg0) { WebApplicationContext webApplicationContext = (WebApplicationContext) arg0.getServletContext() .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); Object obj = webApplicationContext.getBean("ctripHotelService"); //System.out.println(obj); cn.buk.api.service.CtripHotelServiceImpl ctripHotelService = (cn.buk.api.service.CtripHotelServiceImpl) obj; if (ctripHotelService != null) { ctripHotelService.stopService(); System.out.println("ctripHotelService.stopService();"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } obj = null; System.out.println("Obj: " + obj); obj = webApplicationContext.getBean("hotelService"); System.out.println("Obj: " + obj); //if(obj != null) { //cn.buk.hotel.service.HotelServiceImpl hotelService = ; //System.out.println("hotelService: " + hotelService); System.out.println("hotelService.stopService();"); ((cn.buk.hotel.service.HotelServiceImpl) obj).stopService(); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } //} obj = webApplicationContext.getBean("startQuartz"); //System.out.println(obj.getClass().getName()); org.quartz.impl.StdScheduler startQuartz = (org.quartz.impl.StdScheduler) obj; if (startQuartz != null) { //System.out.println("startQuertz.shutdown();"); startQuartz.shutdown(); } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } }