欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

java timer schedule_java怎么再次设置Timer的schedule???

发布时间:2024/9/27 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java timer schedule_java怎么再次设置Timer的schedule??? 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

public class TestTimer {class MyTimerTask extends TimerTask {

private int time; //定时执行时间

public MyTimerTask(){

}

public MyTimerTask(int _time){

this.time = _time;

}

@Override

public void run() {

System.out.println("time:" + time);

System.out.println((time==3000) );

if(time==3000) {

System.out.println("---------------");

throw new RuntimeException("异常");

}

if(time%6000==0) {

time = 0;

}

System.out.println("下次执行时间" + time);

new Timer().schedule(new MyTimerTask(time+1000), time);

}

}

public MyTimerTask init() {

return new MyTimerTask();

}

public static void main(String[] args) throws Exception {

new Timer().schedule(new TestTimer().init(), 2000);

while(true) {

System.out.println(new Date().getSeconds());

Thread.sleep(1000);

}

}

}

不知道能不能满足你的要求

总结

以上是生活随笔为你收集整理的java timer schedule_java怎么再次设置Timer的schedule???的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。