`
tiantian911
  • 浏览: 230610 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

timer example...Post here...

阅读更多
package com.tiantian.servlet;

import com.tiantian.pub.MyTask;
import javax.servlet.*;
import javax.servlet.http.*;

public class TimerListener extends HttpServlet implements
        ServletContextListener {

    private java.util.Timer timer = null;

    public void contextInitialized(ServletContextEvent event) {
        timer = new java.util.Timer(true);
        timer.schedule(new MyTask(event.getServletContext()), 0, 1000 * 10);
    }

    public void contextDestroyed(ServletContextEvent event) {
        timer.cancel();
    }
    }




package com.tiantian.pub;

import java.util.TimerTask;
import javax.servlet.ServletContext;

public class MyTask extends TimerTask {

    private ServletContext context = null;

    public MyTask(ServletContext context) {
        this.context = context;
    }

    public void run() {
        context.log("RUNNING..." + System.currentTimeMillis());
    }
}


1s=1000ms...
if u encountered puzzle, ask reference for advice.
1
0
分享到:
评论

相关推荐

    EurekaLog_7.5.0.0_Enterprise

    5)....Fixed: Dialog auto-close timer may reset without user input 6)....Fixed: Possible hang when quickly loading/unloading EurekaLog-enabled DLL 7)....Fixed: Possible hang in COM DLLs 8)....Fixed: ...

    VB编程资源大全(英文源码 控制)

    It can post messages and recieve messages through the internet.<END><br>8 , optiondemo.zip This example demonstrates how to create realistic Option Buttons in Visual Basic.<END><br>9 , mencrypt....

    VB编程资源大全(英文源码 其它)

    The method of inserting into MSWord may be more useful to most of you..<END><br>48,stopw.zip Example of a stopwatch which does not use a timer control for the calculations, just a simple ...

    计算机网络第六版答案

    Please do not post any solutions on a publicly-available Web site. We’ll be happy to provide a copy (up-to-date) of this solution manual ourselves to anyone who asks. Acknowledgments: Over the ...

    VB编程资源大全(英文源码 网络)

    There are two mini projects included here. The first is called SlotDemo and allows you to send messages or data in a client/server type role. Its uses some very clever programming.<END><br>60 , ...

    ICS delphixe10源码版

    I can't list all contributors here but I want to specially thanks two specially active contributors: - Arno Garrels <arno.garrels@gmx.de> - Angus Robertson <angus@magsys.co.uk> Latest versions: --...

    BobBuilder_app

    Theoretically a b+tree is O(N log k N) or log base k of N, now for the typical values of k which are above 200 for example the b+tree should outperform any binary tree because it will use less ...

    BURNINTEST--硬件检测工具

    Here is a summary of all changes that have been made in each version of BurnInTest. Release 5.3 build 1035 revision 4 WIN32 release 10 November 2008 - Lenovo China specific build. Lenovo system ...

    Bochs - The cross platform IA-32 (x86) emulator

    Changes in 2.4.6 (February 22, 2011): Brief summary : - Support more host OS to run on: - Include win64 native binary in the release. - Fixed failures on big endian hosts. - BIOS: Support for up to...

Global site tag (gtag.js) - Google Analytics