61
A
回答
94
保持到定时参考的地方,并使用:
timer.cancel();
timer.purge();
停止不管它在干什么。您可以使用static int
将此代码放入您正在执行的任务中,以统计您周转的次数,例如,
private static int count = 0;
public static void run() {
count++;
if (count >= 6) {
timer.cancel();
timer.purge();
return;
}
... perform task here ....
}
42
要么就打电话cancel()
on the Timer
,要么就是cancel()
on the TimerTask
如果定时器本身有其他你想要继续的任务。
13
您应该停止您安排的计时器任务: 您的计时器:
Timer t = new Timer();
TimerTask tt = new TimerTask() {
@Override
public void run() {
//do something
};
}
t.schedule(tt,1000,1000);
为了制止:
tt.cancel();
t.cancel(); //In order to gracefully terminate the timer thread
注意,只是取消将计时器不终止正在进行的时间任务。
9
timer.cancel(); //Terminates this timer,discarding any currently scheduled tasks.
timer.purge(); // Removes all cancelled tasks from this timer's task queue.
1
在特定时间唤醒后终止定时器一次(以毫秒为单位)。
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
System.out.println(" Run spcific task at given time.");
t.cancel();
}
}, 10000);
相关问题
- 1. TimerTask扩展类使用java.util.Timer重新计划任务失败
- 2. 如何停止java java.util.Timer()
- 3. 计划任务已停止运行
- 4. Windows任务计划程序C中的计划任务#
- 5. 计划任务
- 6. ColdFusion 10计划任务无法暂停
- 7. Quartz.NET - 计划任务随机停止运行
- 8. Powershell脚本计划任务已停止运行(无法启动)
- 9. 从asp.net开始\停止Windows服务器中的计划任务页面
- 10. AppEngine中的计划任务
- 11. 如何在计划任务终止时运行代码
- 12. 计划任务不会出现在任务计划
- 13. 如何取消任务的计划?
- 14. Exe名称像UEC在计划任务中阻止的update.exe
- 15. 任务计划在春季
- 16. MySQL - 计划任务
- 17. Oracle计划任务?
- 18. 在SQL Server 2008中的计划任务
- 19. spring任务:计划任务默认计划程序池大小
- 20. 如何开发Windows计划任务?
- 21. ASP.NET的计划任务
- 22. Cocoa的计划任务?
- 23. Windows的计划任务
- 24. 如何停止FluentScheduler的任务?
- 25. 在活动中设置计划任务
- 26. 在C#中执行计划任务
- 27. 在.Net中设置计划任务
- 28. 在python中运行计划任务
- 29. 如何停止石英计划程序中的特定作业
- 30. 计划SSIS任务挂在执行过程中的任务
我想取消就足够了,并不需要有净化 – Jacky 2015-05-30 08:43:40
是好到最后根据(Effetive的Java书)添加timer.cancel() – 2015-07-02 05:04:49
@Jacky这是很好的做法兼得,但理论上'取消'本身就可以工作。 – 2016-04-28 00:03:59