调用.cancel()后,定时器不会取消

时间:2015-01-07 14:15:12

标签: java timer timertask

我有一个带有播放和暂停按钮的GUI。按下播放按钮,根据从文件读取的时间戳安排定时器,并根据时间戳将一些数据发布到网络。例如,如果我正在处理的具有以下时间戳:

0.00111 0.0222 0.025585

在第一个时间戳数据发布到网络后,其余的全部时间戳将被发布。

尽管点击暂停按钮,我cancelpurge计时器,我从控制台收到以下错误。

为什么只要我cancelpurge计时器,我就会收到此类错误。

Update_1

是控制台o / p可能只是因为计划了太多的qeued计时器并且在按下暂停后#34; timer.cancel和timer.purge)它们无法运行/预定"了吗?

暂停按钮后

控制台o / p

Exception in thread "TimeStampThread_1_29.372000000003" java.lang.IllegalStateException: 
Timer already cancelled.
at java.util.Timer.sched(Unknown Source)
at java.util.Timer.schedule(Unknown Source)
at org.eclipse.paho.sample.GuiMenuBar$TimeStampTimerThread.run(GuiMenuBar.java:966)
at java.lang.Thread.run(Unknown Source)
Exception in thread "TimeStampThread_1_29.252000000000" java.lang.IllegalStateException: Timer    
already cancelled.
at java.util.Timer.sched(Unknown Source)
at java.util.Timer.schedule(Unknown Source)
at org.eclipse.paho.sample.GuiMenuBar$TimeStampTimerThread.run(GuiMenuBar.java:966)
at java.lang.Thread.run(Unknown Source)
Exception in thread "TimeStampThread_1_29.302000000003" java.lang.IllegalStateException: Timer 
already cancelled.
at java.util.Timer.sched(Unknown Source)
at java.util.Timer.schedule(Unknown Source)

0 个答案:

没有答案