博主资料

留言 加为好友 收藏

用户名:  leuphis

个人统计

用户名: leuphis
等级: 初来乍到
威望: 70
积分: 232
在线时间: 1 小时
日志总数: 21
评论数量: 10
访问次数: 115998
建立时间: 2007-06-02
RSS订阅       手机访问

文章搜索

最近访问的人:

05月19日3只潜力牛..
2008-05-30 13:31:37
MyBlog
2008-04-30 16:16:34
2008-04-29 16:47:17
广州订飞机票=020..
2007-12-22 01:47:25
蓝色天空
2007-09-27 07:21:58
2007-09-06 15:46:25
小猪
2007-08-21 14:51:00
☆°卢京乀°
2007-08-03 07:11:51
虚拟主机
2007-08-03 04:12:37
小风
2007-08-02 06:45:26

日志文章

2007年06月07日 23:41:24

web启动后定时执行任务

1:编写定时执行任务

package test;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class TimeTastDemo implements ServletContextListener {

 public void contextDestroyed(ServletContextEvent arg0) {
  // TODO Auto-generated method stub

 }

 public void contextInitialized(ServletContextEvent arg0) {
  TimerTask task = new TimerTask() {
   public void run() {
    System.out.println("Run Task.....");
   }
  };
  Timer timer = new Timer();
  timer.schedule(task, 0, 2000);

 }
}

 

2:在web.xml添加

 <listener>
      <listener-class>test.TimeTastDemo</listener-class>
  </listener>

类别: j2me |  评论(1) |  浏览(2977) |  收藏
发表评论