SchedulingConfigurer's ScheduledTaskRegistrar should reliably shut down before TaskScheduler [SPR-15067] #19633
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Ruslan Stelmachenko opened SPR-15067 and commented
When I define
taskScheduler
bean withsetWaitForTasksToCompleteOnShutdown(true)
andsetAwaitTerminationSeconds(20)
and at the same time schedule some tasks usingSchedulingConfigurer
and it'sScheduledTaskRegistrar
, thentaskScheduler
never shutdown gracefully because it's queue contains programmatically scheduled tasks (usingtaskRegistrar
), but no one cancels these tasks beforetaskScheduler
tries to shutdown.The second task sits in the scheduler queue and prevents scheduler to
shutdown()
.The task's cancellation lies in
taskRegistrar
'sdestroy()
method, but no one calls it until context bean destruction is in place. At the same time the context waits fortaskScheduler
to terminate to continue beans destruction procedure.When we use
@Scheduled
annotation, then this problem is not present becauseScheduledAnnotationBeanPostProcessor
'sdestroy()
method explicitly callsScheduledTaskRegistrar
'sdestroy()
method, which cancels all the scheduled tasks.But when we register our tasks programmatically, no one calls
ScheduledTaskRegistrar
'sdestroy()
method beforeTaskScheduler
tries toshutdown()
andawaitTermination()
.Maybe we can force somehow to call
ScheduledTaskRegistrar
'sdestroy()
method beforeTaskScheduler
'sdestroy()
method? Of course this can be done manually for example:This workaroud works because the
@Configuration
bean'sdestory()
method called beforeTaskScheduler
's. But I don't know if it is guaranteed or not.I can imagine many workarounds for this but will be better to somehow make it work out of the box, as the
@Scheduled
annotation works.Best regards, Ruslan.
Affects: 4.3.5
Attachments:
Issue Links:
@Bean
methods within@Configuration
classesThe text was updated successfully, but these errors were encountered: