In my Spring Boot APP, I have 12 batch jobs. Each batch job execute at certain time of the day. Surprisingly out of these 12 jobs, only 1 of them is not detected by ShedLock, as a result it gets executed from all nodes running my APP. All 12 jobs are just a method in different @Service annotated classes. Below is how batch job method looks like.
Issue is, if I copy & paste same method in another @Service bean shedLock will detect it, take a lock, create a DB entry & other nodes won't run it, but ShedLock just can't detect it when it is part of MyService.java class.
So what could be wrong with this Bean, it is just like any other Spring Service bean. Why ShedLock just ignores @SchedulerLock annotation in this bean only?
@Service
public class MyService {
@Scheduled(cron = "0 06 15 * * ?", zone = "Etc/GMT")
@SchedulerLock(name = "MyService_myBatchJob", lockAtLeastFor = "PT5M", lockAtMostFor = "PT45M")
public synchronized void myBatchJob() {
System.out.println("Executing job MyService_myBatchJob");
}
}
My pom.xml has this:
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>4.42.0</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-mongo</artifactId>
<version>4.42.0</version>
</dependency>