BotTask.stop() doesn't stop current execution

Issue #606 resolved
Desrever Nu created an issue

TimerTasks cannot be interrupted while they are running. task.cancel(), timer.cancel() , timer.purge() only prevents a new execution.

In our case we have some time-expensive run() tasks, and we want to be able to force-stop them.

After some research, this is the best solution I've found for us :

  1. : each task should have an AtomicBoolean interrupted ; field. BotTask.stop() will set interrupted to true.

Then, in the logic body of run() we constantly monitor that variable and if we find it to be true we simply return;

We could also do something similar and use ScheduledExecutorService. As explained here , we should also perform constant check in the body of run(), exactly like the solution I propose. And it will be also costly migrating all BotTasks to ScheduledExecutorService. This is why I propose going with the first solution .

Comments (5)

  1. Log in to comment