How to stop a scheduled task that was started using @Scheduled annotation?
Option 1: Using a post processor Supply ScheduledAnnotationBeanPostProcessor and explicitly invoke postProcessBeforeDestruction(Object bean, String beanName), for the bean whose scheduling should be stopped. Option 2: Maintaining a map of target beans to its Future private final Map<Object, ScheduledFuture<?>> scheduledTasks = new IdentityHashMap<>(); @Scheduled(fixedRate = 2000) public void fixedRateJob() { System.out.println(“Something to be done every 2 … Read more