1

I read this stackoverflow thread My question is how to cancel it without interrupt. The cancel method of scheduled task is without any parameter and it internally calls ((ScheduledFuture)this.future).cancel(true), which might interrupt the current task.

In my case I don't use Scheduled annotation, instead programmatically create it using taskRegistrar.scheduleFixedRateTask(fixedRateTask) which returns ScheduledTask. Hence I have reference to ScheduledTask and I can invoke cancel() whenever I need. But with the risk of interrupting it. Since the future is package private, I cannot access scheduledTask.future.cancel(false).

Is there another way?

Winster
  • 943
  • 10
  • 28
  • I wanted to control the fixed interval, hence I initially opted scheduleAtFixedRateTask. Later I managed to run it with Scheduled annotation with the help of ApplicationListener. Please check this sample app to know how it works https://github.com/winster/SpringSchedulerDynamic – Winster Jul 02 '20 at 13:28

0 Answers0