gpt4 book ai didi

java - 如何从 20.35 到 23.35 每 30 分钟,一周中的某些天运行一次工作?

转载 作者:行者123 更新时间:2023-11-30 08:01:45 24 4
gpt4 key购买 nike

我遇到了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com