vickzhu

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  151 随笔 :: 0 文章 :: 34 评论 :: 0 Trackbacks
 

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Timer;

import java.util.TimerTask;

publicclass TestTimer {

   

    publicstaticvoid main(String[] args) throws ParseException {

       TestTimer tt=new TestTimer();

       tt.vick();

    }   

    publicvoid vick() throws ParseException{

       Timer timer=new Timer();

       Test timerTask=new Test();

       SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

       Date d=df.parse("2008-08-21 09:00:00");   //在这里设置开始时间

       long delay=d.getTime()-System.currentTimeMillis();   //延迟多少毫秒后开始调用

       long cycle=24*60*60*1000;   //循环调用的时间间隔

       timer.schedule(timerTask, delay, cycle);

    }

}

class Test extends TimerTask{

    privateinti=1;

    publicvoid run() {

       System.out.println("这是第 "+i+" 次调用,时间为:"+new Date());

       i++;

    }

}

posted on 2008-08-20 14:32 筱 筱 阅读(508) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: