以下是代码段:
Timer t = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
//change the timer rate of scheduleAtFixedRate here
}
};
//every 10 sec
t.scheduleAtFixedRate(task, new Date(), 10000);
有人可以告诉我如何将方法t.scheduleAtFixedRate(task, new Date(), 30000)
中的计时器费率从run
实例更改为TimerTask
吗?
非常感谢!
答案 0 :(得分:0)
您无法修改现有的计划,但您可以cancel()
正在执行的TimerTask,并在新的期间重新安排它。
答案 1 :(得分:0)
没有选项可以重新安排已在运行的计时器。您需要取消当前任务并使用新的间隔重新安排它。
Pausing/stopping and starting/resuming Java TimerTask continuously?