![]() |
|
[Java] Stopping a ScheduledExecutorService - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Stopping a ScheduledExecutorService (/showthread.php?tid=6099392) |
Stopping a ScheduledExecutorService - Juice. - Aug 1, 2020 So I have a discord bot where I am trying to send a message every hour. I got that part of it working using the scheduled executor service. It starts when I say !futureson I want to be able to stop it when I send !futuresoff However, I cannot get this to work properly. Here is my code: Code ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);RE: Stopping a ScheduledExecutorService - GenericSkid - Aug 1, 2020 Shutdown() only closes off the service from taking in new runnables. You want to call shutdownNow() https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html#shutdownNow() RE: Stopping a ScheduledExecutorService - Juice. - Aug 1, 2020 (Aug 1, 2020 01:40 PM)GenericSkid Wrote: Shutdown() only closes off the service from taking in new runnables. Code if (args[0].equalsIgnoreCase("!futuresoff")) {I tried this and it does not stop it from running unfortunately :( I also set the scheduled thread pool to 0 instead of 1 at the start. Any other ideas? Or did I not implement that correctly? RE: Stopping a ScheduledExecutorService - knox - Aug 1, 2020 (Aug 1, 2020 02:08 PM)Juice. Wrote: "Does not stop it from running" means that your runnable continues to be called, or that your application does not terminate? It would help to be more explicit about your expectations. Exactly what are you expecting to happen, and what is happening instead? Hopefully this doesn't come off as rude, but from an outsiders perspective, we don't know what "The shutdown thing isn't working like I want it to though" means, because we don't know what your goals are. |