如何在 spring 中设置调度程序任务每 1 分钟运行一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9097771/
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
How to set scheduler task in spring to run every 1 minutes
提问by hudi
now I have this configuration my my scheduler:
现在我的调度程序有了这个配置:
<task:scheduled ref="task" method="run" cron="0 45 22 * * *" />
when this task is executed ? and how I can change it to do this task every minute
这个任务什么时候执行?以及我如何改变它以每分钟完成这项任务
回答by
This task is executed at 22:45:00 every day, every week, every month.
该任务在每天、每周、每月的 22:45:00 执行。
To execute a task every minute, use
要每分钟执行一次任务,请使用
0 * * * * *
回答by nicost
The accepted answer is correct for spring. Other than that, one should be careful whether the target system uses 6 or 5-digits cron.
接受的答案对于春天是正确的。除此之外,应该注意目标系统是使用 6 位还是 5 位 cron。
With 5-digits-crons
带有 5 位数字 cron
0 * * * *schedules to be run "at minute 0"(hence every hour).
0 * * * *计划在“0 分钟”(因此每小时)运行。
The correct answer in this case should be either
在这种情况下,正确答案应该是
* * * * *
* * * * *
or
或者
*/1 * * * *
*/1 * * * *

