我使用 spring 调度程序每 10 分钟发送一次电子邮件,我想在不同的服务器上部署应用程序,所以我使用 shedLock 来防止同时发送多个电子邮件,我遵循文档https://github.com/lukas -krecan/ShedLock
我使用的代码是这个。
@Scheduled(fixedRate = 900000)
@SchedulerLock(name = "scheduledTaskName",lockAtLeastForString = "PT5M", lockAtMostForString = "PT14M")
public void scheduleTaskWithFixedRate() {
log.error("Fixed Rate Task Thread start:: Execution Time - {}"+LocalDateTime.now()+" "+Thread.currentThread().getName());
try {
//10 sec
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.error("Fixed Rate Task Thread End:: Execution Time - {}"+LocalDateTime.now()+" "+Thread.currentThread().getName());
}
有人可以帮忙吗?