Spring 批处理 Cron 表达式:每 3 小时运行一次

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12638000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 05:24:17  来源:igfitidea点击:

Spring batch Cron expression: to run every 3 hours

springcronspring-batch

提问by user1705935

I want my spring batch job to run every 3 hours

我希望我的春季批处理作业每 3 小时运行一次

I used expression * * */3 * * ?this starts the job at the hour that is divisible by 3 e.g. say the server was started at 2 PM the job starts executing only at 3 PM - so far so good but the job keeps starting every second! Is it because I used * in the 1st position?

我使用了表达式,* * */3 * * ?它在可被 3 整除的小时开始工作,例如说服务器在下午 2 点启动,工作仅在下午 3 点开始执行 - 到目前为止一切顺利,但工作每秒都在开始!是因为我在第一个位置使用了 * 吗?

I tried 0 0 */3 * * ?but it is erroring out. What is the best way to achieve this?

我试过了,0 0 */3 * * ?但它出错了。实现这一目标的最佳方法是什么?

回答by Christoph Leiter

The format is

格式是

second, minute, hour, day, month, weekday

秒、分、时、日、月、工作日

so the correct cron expression should be

所以正确的 cron 表达式应该是

0 0 */3 * * *

If that doesn't work, what's the exact error message you are getting?

如果这不起作用,您收到的确切错误消息是什么?

回答by N. Pradeep

The right syntax to make the script to run every 3 hours is as below.

使脚本每 3 小时运行一次的正确语法如下。

0 0 0/3 * * ?