0

We have written a simple application in spring boot that triggers a cron job. We are able to launch it successfully. Below is pice of code.

CronTask task = new CronTask(new Runnable() {

            @Override
            public void run() {
                System.out.println("Job running ...")
            }
        }, cronExpression);

        taskRegistrar.addCronTask(task);
        taskRegistrar.afterPropertiesSet();

Now how to unregister/kill/destroy/remove the task started by me.

I can get the corn task back from the registry using

this.taskRegistrar.getCronTaskList();

But don't see a method in the registry to unregister a task nor any method in task to destroy it.

Ameya
  • 1,914
  • 4
  • 29
  • 55
  • this might work. https://stackoverflow.com/questions/44644141/how-to-stop-a-scheduled-task-that-was-started-using-scheduled-annotation – Haluk Özen Feb 26 '21 at 06:27
  • @HalukÖzen I have checked that solution, there the answer that has been marked right does not show how to stop although he is implementing a custom fixed rate scheduler. Where he is putting his tasks into an identity registry/map. There are some more answers in the tread bit confusing or incomplete. Currently, I am programmatically injecting jobs as these jobs need to be introduced at runtime. If someone can give the code or I found out will post it. – Ameya Feb 26 '21 at 06:49

0 Answers0