Java 在石英调度程序中每 30 秒执行一次 cron 表达式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35214149/
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
cron expression for every 30 seconds in quartz scheduler?
提问by user1950349
I am using Quartz Scheduler to run my jobs. I want to run my job every thirty seconds. What will be my cron expression for that?
我正在使用 Quartz Scheduler 来运行我的作业。我想每三十秒运行一次我的工作。我的 cron 表达式是什么?
For every one minute, I am using below cron expression:
每一分钟,我都使用以下 cron 表达式:
<cron-expression>0 0/1 * 1/1 * ? *</cron-expression>
What it will be for every thirty seconds?
每三十秒会是多少?
采纳答案by Ian Mc
The first element represents the seconds; to run at second 0 and 30 use the following:
第一个元素代表秒;要在 0 秒和 30 秒运行,请使用以下命令:
0/30 0/1 * 1/1 * ? *
0/30 0/1 * 1/1 * ? *
回答by Shailesh
If you are using Spring framework, make use of @PostConstruct
annotation and then @Scheduled(cron=0 0/15 * 1/1 * ?)
to trigger now, now+15min and so on.
如果您使用的是 Spring 框架,请使用@PostConstruct
注解然后@Scheduled(cron=0 0/15 * 1/1 * ?)
触发 now、now+15min 等。
回答by hariprasad
The same effect we can reach (Quartz Spring) using more simpler construction:
我们可以使用更简单的构造达到相同的效果(石英弹簧):
0/30 * * * * ? *
The last asterisk we can omit.
我们可以省略最后一个星号。
0/30 * * * * ?
回答by Jar Yit
I hope this answer will help you. Please define the cron expression the below
我希望这个答案对你有帮助。请定义下面的 cron 表达式
0/30 * * * * ? *
And then you go this website and test Cron Expression Generator & Explainer - Quartz.
然后你去这个网站并测试Cron Expression Generator & Explainer - Quartz。