I have following scheduled job which runs in multiple instances.
@Scheduled(fixedRate = 10000)
@SchedulerLock(name = "AwesomeJob", lockAtLeastForString = "5S", lockAtMostForString = "5S")
public void awesomeJob() throws InterruptedException {
for (int i = 0; i < 5; i++) {
log.info("Processing {}", i);
Thread.sleep(100000L);
}
}
I know that If the task takes longer than lockAtMostFor the resulting behavior may be unpredictable. Is there a way to avoid that behavior by using SimpleLock.extend method? I am using JdbcLockProvider. I got this idea from https://github.com/lukas-krecan/ShedLock/issues/151 .
The easiest way is to set lockAtMostFor
to a higher value. It's just a safety net for cases when the node executing the task dies so it should not be a problem.
If you can not do it for some reason, you can use extend
method as described in the issue you provided. But it means you have to manage the lock manually. There is currently no functionality allowing to extend a lock created automatically using AOP.