SSH框架监听器

测试可用

web.xml  配置监听器
<listener>
<listener-class>com.iAe.common.auto.ServletListener</listener-class>   //servlet对应的位置
</listener>



写一个servlet

public class ServletListener implements ServletContextListener {
    private final Timer timer = new Timer();
    private Calendar calFirst=Calendar.getInstance(); //第一个任务的启动时间
    private Calendar calSecond=Calendar.getInstance();    //第二个任务的启动时间
    private Calendar calThird=Calendar.getInstance();    //第二个任务的启动时间
    public void contextDestroyed(ServletContextEvent se) {
        timer.cancel();

    }

    public void contextInitialized(ServletContextEvent se) {
       
        //String firstTime=se.getServletContext().getInitParameter("firstTime");
        //System.out.println(firstTime);
        //String secondTime=se.getServletContext().getInitParameter("secondTime");
        //System.out.println(secondTime);
        //设置第一启动时间23:30
        calFirst.set(Calendar.HOUR_OF_DAY, 23);
        calFirst.set(Calendar.MINUTE,30);
        //启动第一个任务
        timer.schedule(new FirstTimerTask(), calFirst.getTime(),24*60*60*1000);
        //设置第二启动时间23:45
        calSecond.set(Calendar.HOUR_OF_DAY, 23);
        calSecond.set(Calendar.MINUTE, 45);
        //启动第二个任务
        timer.scheduleAtFixedRate(new SecondTimerTask(), calSecond.getTime(),24*60*60*1000);
       
        //设置第三启动时间00:05
        calThird.set(Calendar.HOUR_OF_DAY, 0);
        calThird.set(Calendar.MINUTE, 5);
        //启动第三个任务
        timer.scheduleAtFixedRate(new ThirdTimerTask(), calThird.getTime(),24*60*60*1000);

        //设置第四启动时间00:10
        calThird.set(Calendar.HOUR_OF_DAY, 0);
        calThird.set(Calendar.MINUTE, 10);
        //启动第四个任务
        timer.scheduleAtFixedRate(new ForthTimerTask(), calThird.getTime(),24*60*60*1000);
    }
    public class FirstTimerTask extends TimerTask{
        public void run() {
            makeTonRent();   
            clientStoreReport();
        }
    
    }

 

 

在这里面可以获得aplicationContext.xml文件,再进行数据库方面操作。

 

 

 

 

转载于:https://www.cnblogs.com/lzmblog/archive/2012/11/29/2795519.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值