简体   繁体   中英

How to cancel all the scheduled tasks with TaskScheduler object?

Hey I'm using with TaskScheduler object to schedule a few task in a different time.

I can't find the way to stop all the tasks, the only way I found is to restart my server(application) and I don't want to do it.

I have been trying to set the executer to null but it didn't work.

I'm attaching my code:

    private TaskScheduler executor;

    public void createSched() {
    Runnable task;
    task=()-> LOGGER.info("hello");
    TimeZone time=TimeZone.getTimeZone("UTC");
    executor.schedule(task, new CronTrigger("0,5,10,15,20,25,30 * * * * ?",time));
   // this.executor=null;
}

after the code above the tasks keep going and I cant stop it anymore...

Try this link

What you need to do is to keep a hash map of all the tasks from ScheduledFuture type and then you will be able to cancel the task.

Hope it helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM