package com.yihu.ehr.common; import com.yihu.ehr.framework.constrant.DateConvert; import com.yihu.ehr.framework.util.log.LogService; import com.yihu.ehr.framework.util.quartz.QuartzManager; import org.apache.commons.beanutils.ConvertUtils; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.util.Date; /** * 项目启动执行 * add by hzp at 2016-01-25 */ public class ApplicationStart implements ServletContextListener { private static int rebootCount = 0; @Override public void contextInitialized(ServletContextEvent context) { //使用自定义转化器转化时间格式 ConvertUtils.register(new DateConvert(), Date.class); //initQuartz();//启动任务 } @Override public void contextDestroyed(ServletContextEvent context) { destroyedQuartz(); } /** * 初始化任务 * @return */ public void initQuartz(){ try { QuartzManager.startJobs(); } catch(Exception e){ LogService.getLogger().error(" Quartz job initing Exception " + e.getMessage()); } } /** * 终止任务 */ public void destroyedQuartz(){ try { QuartzManager.shutdownJobs(); } catch(Exception e){ LogService.getLogger().error(" Quartz job destroying Exception " + e.getMessage()); } } }