zoukankan      html  css  js  c++  java
  • 利用ServletContextListener实现定时任务

    package com.ed.cnc.servletListener;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客import javax.servlet.ServletContextEvent;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客import javax.servlet.ServletContextListener;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客import com.ed.cnc.city.StatisticsTask;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客/** *//**

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 * 统计ContextListener

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 * @author westd

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 *

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 */

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客/** *//**

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 * @author westd

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 *

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 */

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客public class StatisticsContextListener implements ServletContextListener

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    private java.util.Timer timer = null;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    /** *//**

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * 这个方法在Web应用服务做好接受请求的时候被调用。

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     */

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    public void contextInitialized(ServletContextEvent event) 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        timer = new java.util.Timer(true);

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        event.getServletContext().log("定时器已启动"); 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        timer.schedule(new StatisticsTask(event.getServletContext()), 0, 60*60*1000);//每隔1小时

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        event.getServletContext().log("已经添加任务调度表");

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    }

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    /** *//**

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * 这个方法在Web应用服务被移除,没有能力再接受请求的时候被调用。

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     */

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    public void contextDestroyed(ServletContextEvent event)

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        timer.cancel();

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        event.getServletContext().log("定时器销毁");

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    }

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客}

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    一个继承于TimerTask的一个类:StatisticsTask.java

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客package com.ed.cnc.city;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客import java.util.Calendar;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客import java.util.TimerTask;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客import javax.servlet.ServletContext;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客/** *//**

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 * 统计任务

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 * @author westd

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 *

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客 */

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客public class StatisticsTask extends TimerTask

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    private static final int STATISTICS_SCHEDULE_HOUR = 0;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    private static boolean isRunning = false;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    private ServletContext context = null;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    public StatisticsTask(ServletContext context)

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        this.context = context;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    }

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    @Override

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    public void run()

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        Calendar cal = Calendar.getInstance(); 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        //System.out.println(isRunning);

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        if (!isRunning) 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客            if (STATISTICS_SCHEDULE_HOUR == cal.get(Calendar.HOUR_OF_DAY)) //查看是否为凌晨

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客            利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                isRunning = true; 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                context.log("开始执行指定任务");

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                //TODO 添加自定义的详细任务

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                executeTask();

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                //指定任务执行结束

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                isRunning = false;

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客                context.log("指定任务执行结束"); 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客            } 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        } 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        else 

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客            context.log("上一次任务执行还未结束");

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        }

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    }

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    /** *//**

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     * 执行任务

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客     */

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    public void executeTask()

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客{

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        System.out.println("任务1利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客");

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        System.out.println("任务2利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客");

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客    }

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客}

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客

    web.xml中添加如下代码:

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客<listener>

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客        <listener-class>com.ed.cnc.servletListener.StatisticsContextListener</listener-class>

    利用ServletContextListener实现定时任务  - 冯冯 - 冯冯的博客</listener>

  • 相关阅读:
    迅为i.MX6ULL终结者Linux MISC驱动运行测试
    迅为IMX6Q开发板非设备树uboot-修改默认环境变量
    Android固件编译-迅为3399开发板Android8系统编译
    迅为4412开发板-实验LEDS驱动一
    迅为i.MX6ULL终结者设备树下的Platform驱动运行测试
    迅为i.MX6ULL终结者设备树下的Platform驱动实验程序编写
    项目实战-广域网智能家居-把mosquitto移植到arm上
    迅为-iMX6ULL开发板-设置yocto文件系统开机自启动
    muduo库中的核心:std::bind和std::function
    浅析muduo库中的定时器设施
  • 原文地址:https://www.cnblogs.com/kuyuyingzi/p/4266342.html
Copyright © 2011-2022 走看看