作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了 cron 表达式的问题。从周四到周日,我必须每 30 分钟运行一次方法。它的时间将从 20:35 分钟开始到 23:35 分钟。
Cron 表达式:
"0 35/30 20-23 ? * THU-SUN";
据我了解;我的方法将在星期四的 20:35 分钟每 30 分钟调用一次,直到星期日。
我的期望:
方法将按照以下时间调用:
Thu May 19 20:35:00 IST 2016
Thu May 19 21:05:00 IST 2016
Thu May 19 21:40:00 IST 2016
但是;方法 get 按以下时间调用:
Thu May 19 20:35:00 IST 2016
Thu May 19 21:35:00 IST 2016
Thu May 19 22:35:00 IST 2016
谁能帮帮我。为什么 cron 表达式每 1 小时评估一次。??
这是代码示例:
@Scheduled(cron="0 35/30 20-23 ? * THU-SUN")
public void startInboundSFTPChannel(){
logger.info("Cron job started....");
downloadSftpFilesController();
}
最佳答案
如果希望命令从周四到周日每天20.35到23.35运行,可以分两步定义:
35 20 ? * THU-SUN
5-59 21-23 ? * THU-SUN
没有简单的方法可以仅在 cron 表达式中进行设置,因为您不希望它在 20.05 运行。
即:在 20 点,在第 35 分钟运行。在 21 到 23 点,every 30 minutes with an offset of 5 minutes .
我的回答基于这种格式:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
关于java - 如何从 20.35 到 23.35 每 30 分钟,一周中的某些天运行一次工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37319986/
我是一名优秀的程序员,十分优秀!