我想做一个计时器,当有事情发生时它会重新启动:
public static Timer timer;
public myTimer(long MAC, String ipAddress){
timer = new Timer();
timer.schedule(timerTask, 120000);
}
public void update(){
timer.cancel();
timer = new Timer();
timer.schedule(timerTask, 120000);
}
创建新计划时遇到问题,出现以下错误:
java.lang.IllegalStateException: Task already scheduled or cancelled
at java.util.Timer.sched(Timer.java:358)
at java.util.Timer.schedule(Timer.java:170)
at spb.keepAliveTimer.update(keepAliveTimer.java:37)
at spb.keepAlive.update(keepAlive.java:58)
at spb.receptor.keepAlive(receptor.java:475)
at spb.receptor.run(receptor.java:118)
at java.lang.Thread.run(Thread.java:662)
我不知道我该怎么做!谢谢!