Scheduled tasks aren't cancelled on ScheduledTaskRegistrar destruction anymore [SPR-14286] #18858
Comments
Juergen Hoeller commented Indeed, as of 4.3 RC2, |
Romain Moreau commented I looked at ScheduledAnnotationBeanPostProcessor and any Set that is a value of the scheduledTasks map will only contain one task associated to the last For instance, given the following class, Spring 4.3.RC2 will only cancel the task associated to the scheduled3 method, the tasks associated to the scheduled1 and the scheduled2 methods won't be cancelled. @Component
public class Scheduler {
private static final Logger LOGGER = LoggerFactory.getLogger(Scheduler.class);
@Scheduled(cron = "*/30 * * * * *")
public void scheduled1() {
LOGGER.info("1");
}
@Scheduled(cron = "0 0 0 * * *")
public void scheduled2() {
LOGGER.info("2");
}
@Scheduled(cron = "15 * * * * *")
public void scheduled3() {
LOGGER.info("3");
}
} |
Juergen Hoeller commented Good catch! Addressed in master now; please give the upcoming |
Romain Moreau commented I tried the latest SNAPSHOT build with your changes and it works for me, thanks! |
Romain Moreau opened SPR-14286 and commented
With Spring 4.3.0.RC1, when ScheduledTaskRegistrar was destroyed, scheduled futures were cancelled correctly.
Now, with Spring 4.3.0.RC2, when ScheduledTaskRegistrar is destroyed, scheduled tasks aren't cancelled because the scheduledTasks collection used to iterate the tasks to cancel is empty.
Here's below the code for a quick and dirty reproduction case.
To run with Spring 4.3.0.RC1, replace the spring-boot-starter-parent version with 1.4.0.M2.
With Spring 4.3.0.RC1, you'll see in the log "1 scheduled found" as expected.
With Spring 4.3.0.RC2, you'll see in the log "0 scheduled found" (scheduledTasks set is empty).
Affects: 4.3 RC2
Issue Links:
Referenced from: commits 3576ff0
The text was updated successfully, but these errors were encountered: