Add a way to set executeExistingDelayedTasksAfterShutdown from ThreadPoolTaskScheduler #26719
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Observed behaviour
ThreadPoolTaskScheduler
is used for methods annotated with@Scheduled
.In the example of a method which is to be run at a specific time e.g.
@Scheduled( cron = "0 0 2 * * *" )
(run at 2 a.m.), theScheduledThreadPoolExecutor
withinThreadPoolTaskScheduler
knows that it must execute this at the future time.However, when I call
threadPoolTaskScheduler.shutdown()
the shutdown is being blocked until the queued task has been exectued. In the above example this would be, 2 a.m. + the time it takes to execute the task. Note that this behaviour only happens when I have configured a long enough termination period withthreadPoolTaskScheduler.setAwaitTerminationSeconds
.One other point. I know the
ThreadPoolTaskScheduler
will get automatically shutdown when the application shuts down, but I am doing it manually for other reasons which I won't go into in this issue.In summary:
ThreadPoolTaskScheduler
has a long terimation period (setAwaitTerminationSeconds
)threadPoolTaskScheduler.shutdown()
My requirement here is that the
ThreadPoolTaskScheduler
should shut down faster by only waiting for those tasks which are currently being processed. Tasks which are scheduled for a future time will not be executed.Current workaround
I found a method on
ScheduledThreadPoolExecutor
namedsetExecuteExistingDelayedTasksAfterShutdownPolicy
which seems to do what I need.When I set this value to
false
by configuring a customThreadPoolTaskScheduler
I observe the desired behaviour.Suggested improvement
Could we configure this more easily using a property on the
ThreadPoolTaskScheduler
? In theThreadPoolTaskScheduler
methodinitializeExecutor
it already does similar configurations e.g. for theremoveOnCancelPolicy
If being able to set this configuration would be valuable for this framework, then maybe this would be a suitable place to put it?
The end result of how to use the new functionality might look like this:
The text was updated successfully, but these errors were encountered: