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???的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: html翻转切换div效果,图片翻转效果
- 下一篇: ansible 修改文件变量_基于ans