How to stop immediately the task scheduled in Java.util.Timer class

前端 未结 2 586
渐次进展
渐次进展 2020-12-18 06:12

I tried everything. This one too How to stop the task scheduled in Java.util.Timer class

I have one task that implements java.util.TimerTask

I call that t

2条回答
  •  春和景丽
    2020-12-18 06:43

    if your timer is using some sort of file/socket etc, you can close that object from outside the timer, and the timer task will throw an exception, and you can use it to stop the timer.

    but in general you need some sort of poison pill to successfully stop a separate thread/timer.

提交回复
热议问题