Skip to content

Commit a0c80ff

Browse files
committed
Destroy local TaskSchedulerRouter which may contain local executor
See gh-20818
1 parent a861453 commit a0c80ff

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public class ScheduledAnnotationBeanPostProcessor
144144
@Nullable
145145
private ApplicationContext applicationContext;
146146

147+
@Nullable
148+
private TaskSchedulerRouter localScheduler;
149+
147150
private final Set<Class<?>> nonAnnotatedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>(64));
148151

149152
private final Map<Object, Set<ScheduledTask>> scheduledTasks = new IdentityHashMap<>(16);
@@ -251,10 +254,10 @@ private void finishRegistration() {
251254
this.registrar.setScheduler(this.scheduler);
252255
}
253256
else {
254-
TaskSchedulerRouter router = new TaskSchedulerRouter();
255-
router.setBeanName(this.beanName);
256-
router.setBeanFactory(this.beanFactory);
257-
this.registrar.setTaskScheduler(router);
257+
this.localScheduler = new TaskSchedulerRouter();
258+
this.localScheduler.setBeanName(this.beanName);
259+
this.localScheduler.setBeanFactory(this.beanFactory);
260+
this.registrar.setTaskScheduler(this.localScheduler);
258261
}
259262

260263
if (this.beanFactory instanceof ListableBeanFactory lbf) {
@@ -637,6 +640,9 @@ public void destroy() {
637640
}
638641
}
639642
this.registrar.destroy();
643+
if (this.localScheduler != null) {
644+
this.localScheduler.destroy();
645+
}
640646
}
641647

642648
}

0 commit comments

Comments
 (0)