java - Spring Boot Job Scheduler fixedDelay 和 cron
问题描述
我正在运行一个需要 5-10 秒才能完成的 Spring Boot 计划进程。完成后,60 秒后该过程再次开始(请注意,我没有使用 fixedRate):
@Scheduled(fixedDelay=60_000)
现在,我想限制它在周一至周五上午 9 点到下午 5 点每分钟运行一次。我可以做到这一点
@Scheduled(cron="0 * 9-16 ? * MON-FRI")
这里的问题是它的行为类似于 fixedRate - 该过程每 60 秒触发一次,而不管完成上一次运行所花费的时间......
有什么方法可以结合这两种技术?
解决方案
试试下面:
@Schedules({
@Scheduled(fixedRate = 1000),
@Scheduled(cron = "* * * * * *")
})
推荐阅读
- windows - 什么是压缩 GUID,为什么要使用它?
- javascript - 实现格路径计数的递归
- javascript - 如何在javascript中的变量中定义变量
- javascript - 如何向 Angular 应用程序发出 CORS HTTP 请求
- android - 代理设置不适用于 Chrome Webview
- c# - ASP.NET 设置用户身份和 IsAuthenticated = true
- azure-ad-b2c - 更新 Azure B2C 自定义策略中的显示名称
- sinch - Android Sinch PubNubListener:6 次尝试后永久订阅失败
- c# - PlaceHolder 重复按钮单击插入错误太多参数
- ruby - 心理 to_yaml 不替换字符串数组