简体   繁体   English

第35分钟的每小时运行一次的cron cron

[英]spring cron for running every hour at 35th minute

I have a job that is scheduled to run every hour and I am using spring cron (0 0/35 * * * ). 我有一份计划每小时运行的工作,并且正在使用spring cron(0 0/35 * * *)。 I am expecting the job to run at the 35th minute every hour but I noticed that the job gets triggered at the 35th minute and also at top of the hour. 我期望该作业在每小时的第35分钟运行,但我注意到该作业在第35分钟以及每小时的顶部触发。 I am not sure why, any suggestions? 我不确定为什么,有什么建议吗?

Thanks, Karthik 谢谢,卡尔提克

根据Spring CronSequenceGenerator的文档/35 in 0 0/35 * * *实际上表示“每分钟是35的倍数”,其中包括0-如果您只希望它在每小时后的35分钟触发,请使用0 35 * * * * (包括所需的所有6个参数)。

您的cron表达式不正确,因此请将其更改为0 */35 * * * ,该表达式仅每35分钟运行一次

I think your fields are out of order. 我认为您的字段混乱。 The Spring Cron documenation seems to say that Spring uses standard cron expressions. Spring Cron文档似乎表明Spring使用标准cron表达式。 https://crontab.guru is a good tool for checking cron expressions. https://crontab.guru是检查cron表达式的好工具。

https://crontab.guru/#0_0/35_ _ _* shows https://crontab.guru/#0_0/35_ _ _ *显示

“At minute 0 past every 35th hour from 0 through 23.” “每35小时从0到23的0分钟。”

Whereas https://crontab.guru/#35_ _ _ _ shows https://crontab.guru/#35_ _ _ _显示

“At minute 35.” “第35分钟。”

I think you need to use 35 * * * * 我认为您需要使用35 * * * *

Yes. 是。 Cron starts minutes at beginning of each hour (as we mention * for hour field). Cron在每个小时的开头开始分钟(如我们在小时字段中提到的*)。 An alternative way of achieving your goal ( executing a task at every 35th minute )can be as follows - 达成目标的另一种方法( 每35分钟执行一次任务 )可以如下-

Make your cron trigger for every 5 minutes and increment a counter everytime the cron is triggered. 使cron触发器每5分钟触发一次,并在每次cron触发时增加一个计数器。 Once the counter reaches 7 (ie 35 mins in your case), execute your goal and set the counter back to 0. 一旦计数器达到7(即您的情况下为35分钟),请执行目标并将计数器重新设置为0。

And if you want your goal to be executed at 35th minute of each hour , you should try 如果您希望在每小时的第35分钟执行目标,则应尝试

35 * * * *

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM