whycxzp
2022-03-16 79daef48c2b0d519e1b50a6a100c62a7651b6a06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.whyc.listener;
 
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();
    }
}