Destroy local TaskSchedulerRouter which may contain local executor

See gh-20818
This commit is contained in:
Juergen Hoeller 2023-07-08 15:55:25 +02:00
parent a8614531ab
commit a0c80ffc06
1 changed files with 10 additions and 4 deletions

View File

@ -144,6 +144,9 @@ public class ScheduledAnnotationBeanPostProcessor
@Nullable @Nullable
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Nullable
private TaskSchedulerRouter localScheduler;
private final Set<Class<?>> nonAnnotatedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>(64)); private final Set<Class<?>> nonAnnotatedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>(64));
private final Map<Object, Set<ScheduledTask>> scheduledTasks = new IdentityHashMap<>(16); private final Map<Object, Set<ScheduledTask>> scheduledTasks = new IdentityHashMap<>(16);
@ -251,10 +254,10 @@ public class ScheduledAnnotationBeanPostProcessor
this.registrar.setScheduler(this.scheduler); this.registrar.setScheduler(this.scheduler);
} }
else { else {
TaskSchedulerRouter router = new TaskSchedulerRouter(); this.localScheduler = new TaskSchedulerRouter();
router.setBeanName(this.beanName); this.localScheduler.setBeanName(this.beanName);
router.setBeanFactory(this.beanFactory); this.localScheduler.setBeanFactory(this.beanFactory);
this.registrar.setTaskScheduler(router); this.registrar.setTaskScheduler(this.localScheduler);
} }
if (this.beanFactory instanceof ListableBeanFactory lbf) { if (this.beanFactory instanceof ListableBeanFactory lbf) {
@ -637,6 +640,9 @@ public class ScheduledAnnotationBeanPostProcessor
} }
} }
this.registrar.destroy(); this.registrar.destroy();
if (this.localScheduler != null) {
this.localScheduler.destroy();
}
} }
} }