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效果,图片翻转效果
- 下一篇: web 前端 如何分享到instagra