java Quartz 中每 50 秒一次的 Cron 表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15458254/
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-10-31 19:40:22  来源:igfitidea点击:

Cron expression every 50 seconds in Quartz

javaquartz-schedulerquartz.net

提问by Yosefarr

I'm running my Jobs using Quartz with a cron expression every 50 seconds:

我每 50 秒使用带有 cron 表达式的 Quartz 运行我的作业:

Cron_Expression = "0/50 * * * * ?"

What happens is that my job runs at the seconds: 50, 60, 50, 60,...and not every 50 seconds! and does not run at the second "0".

发生的情况是我的工作在以下几秒内运行:50、60、50、60……而不是每 50 秒!并且不会在第二个“0”处运行。

What is the right cron expression every 50 seconds starting at 0?

从 0 开始每 50 秒正确的 cron 表达式是什么?

回答by darrenmc

The '/' syntax specifies the increment during the period and not a repeat interval. Admittedly a subtle and confusing difference.

'/' 语法指定周期内的增量而不是重复间隔。不可否认,这是一个微妙而令人困惑的差异。

In this case there is only one available increment (50 seconds) during the 1 minute period. The first number specifies the value to start with, in this case 0. Specifying '*' before the '/' is equivalent to specifying 0. So the job will only fire on the minute (0 and 60 are interchangeable) and at 50 seconds.

在这种情况下,1 分钟内只有一个可用的增量(50 秒)。第一个数字指定要开始的值,在本例中为 0。在 '/' 之前指定 '*' 等效于指定 0。因此作业只会在分钟(0 和 60 可互换)和 50 秒时触发.

If the period can be divided by multiple increments, eg 0/10 then it will fire for each at each of those times, eg at 10, 20, 30 etc seconds.

如果该时间段可以被多个增量分割,例如 0/10,那么它将在每个时间段(例如在 10、20、30 秒等)触发。

If you want a job to trigger at a regular interval then you can use a Quartz SimpleTriggerwith a repeatIntervalspecified.

如果你在有规律的间隔需要一份工作来触发,那么你可以使用一个石英SimpleTriggerrepeatInterval指定。