package com.whyc.Listeners;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextListener;
|
import javax.servlet.annotation.WebListener;
|
import java.util.Timer;
|
|
@WebListener
|
public class TaskListener implements ServletContextListener {
|
|
/**一月执行一次*/
|
public static final Long ONE_MONTH = DateUtils.MILLIS_PER_DAY*30;
|
/** 一天执行一次*/
|
public static final Long ONE_DAY = DateUtils.MILLIS_PER_DAY;
|
|
/**调试用*/
|
//public static final Long ONE_MONTH_DEBUG = DateUtils.MILLIS_PER_SECOND*10;
|
|
private Timer timer;
|
|
@Override
|
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
// Calendar instance = Calendar.getInstance();
|
// instance.set(Calendar.HOUR_OF_DAY,23);
|
// instance.set(Calendar.MINUTE,59);
|
// instance.set(Calendar.SECOND,59);
|
// Date firstDate = instance.getTime();
|
// timer = new Timer("Task定时任务",true);
|
// /*//每月刷新数据库表中天气支持城市-聚合平台,弃用
|
// timer.schedule(new WeatherTask(),firstDate,ONE_MONTH);*/
|
//
|
// //每日清空Application中的weather
|
// timer.schedule(new ClearApplicationWeatherTask(),firstDate,ONE_DAY);
|
//
|
// //告警工单功能是否开启
|
// if(PropertiesUtil.props.getProperty("alarm.task.switch").toUpperCase().equals("ON")) {
|
// //刷新告警记录生成工单,频率为1秒1次
|
// timer.schedule(new AlarmTask(), 1000, 1000);
|
//
|
// //告警工单自动派单,频率为1秒钟1次
|
// timer.schedule(new AlarmDispatchTask(), 1000, 1000);
|
// }
|
//
|
// //配置文件控制告警短信发送功能是否开启
|
// //告警短信发送,频率为10秒钟1次
|
// if(PropertiesUtil.props.getProperty("message.switch").toUpperCase().equals("ON")){
|
// timer.schedule(new AlarmMessageTask2(),1000*10,1000*10);
|
// }
|
// //账号自动扫描策略,频率为1天
|
// timer.schedule(new AccountScanTask(),1000,ONE_DAY);
|
// //账号登录失败锁定相关策略,频率为2秒
|
// timer.schedule(new AccountLockStrategyTask(servletContextEvent.getServletContext()),1000,2000);
|
// //防重放功能随机码清除,频率为2秒
|
// timer.schedule(new PreventTryTask(servletContextEvent.getServletContext()),1000,2000);
|
}
|
|
@Override
|
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
timer.cancel();
|
}
|
}
|