问题
I'm running my Jobs using Quartz with a cron expression every 50 seconds:
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".
What is the right cron expression every 50 seconds starting at 0?
回答1:
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.
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.
If you want a job to trigger at a regular interval then you can use a Quartz SimpleTrigger
with a repeatInterval
specified.
来源:https://stackoverflow.com/questions/15458254/cron-expression-every-50-seconds-in-quartz