Java Cron中问号的重要性

时间:2022-07-10 08:00:25

Source Wikipedia:

Question mark (?) is used instead of '*' for leaving either day-of-month or day-of-week blank.

使用问号(?)代替'*'来保留日期或星期几空白。

The above statement is not making much sense to me.

上面的陈述对我来说没有多大意义。

So if I write some cron as 0 0 0 ? * * then does it mean first of every month or it means it will execute daily?

所以,如果我写一些cron为0 0 0? * *那么它是指每个月的第一个还是意味着它将每天执行?

It is a bit confusing as Java crons start with seconds while other crons start with minute.

这有点令人困惑,因为Java crons以秒开始,而其他crons以分钟开始。

3 个解决方案

#1


-8  

I am not Cron expert

我不是Cron专家

But according www.cronmaker.com it is executed daily.

但根据www.cronmaker.com,它每天执行。

#2


70  

According to the Quartz CronTrigger tutorial (Quartz is used by www.cronmaker.com, referenced above), the ? wildcard is only used in the day of month and day of week fields:

根据Quartz CronTrigger教程(Quartz由www.cronmaker.com使用,如上所述),?通配符仅用于星期几和星期几字段:

? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.

? (“无特定值”) - 当您需要在允许该字符的两个字段之一中指定某些内容时有用,而不是另一个字段。例如,如果我希望我的触发器在该月的某个特定日期(例如,第10天)触发,但不关心恰好在一周的哪一天,我会在当天放置“10” -month字段,和“?”在星期几的字段中。

I guess * isn't appropriate here because * means execute on every day of the week, which contradicts the rule saying that it should only run on the 10th of the month.

我想这里*是不合适的,因为*意味着在每周的每一天都执行,这违反了规则,它应该只在该月的10日运行。

#3


-3  

I know it's an old question but for posterity, it's explained here : http://www.nncron.ru/help/EN/working/cron-format.htm#STARTTIME

我知道这是一个古老的问题,但对后代而言,这里有解释:http://www.nncron.ru/help/EN/working/cron-format.htm#STARTTIME

Both in classic and extended modes, nnCron users can use a "nonstandard" character "?" in the first four fields of cron format. It stands for time of nnCron startup, i. e. when a field is processed, startup time will be substituted for the question mark: minutes for Minute field, hour for Hour field, day of the month for Day of month field and month for Month field.

在经典模式和扩展模式下,nnCron用户都可以使用“非标准”字符“?”在cron格式的前四个字段中。它代表nnCron启动的时间,i。即处理字段时,启动时间将替换问号:分钟字段分钟,小时字段小时,月日字段月份日期和月份字段月份。

For example, if you write the following:

例如,如果您编写以下内容:

Time: ? ? * * * * the task will be executed on nnCron startup and then will be executed daily at the same time (unless the user doesn't restart nnCron, of course): question marks will be "replaced" by nnCron startup time. For example, if nnCron was started at 8:25, question marks will be substituted this way:

时间: ? ? * * * *任务将在nnCron启动时执行,然后每天同时执行(当然,除非用户没有重启nnCron):问号将被nnCron启动时间“替换”。例如,如果nnCron在8:25启动,则问号将以这种方式替换:

Time: 25 8 * * * *

时间:25 8 * * * *

#1


-8  

I am not Cron expert

我不是Cron专家

But according www.cronmaker.com it is executed daily.

但根据www.cronmaker.com,它每天执行。

#2


70  

According to the Quartz CronTrigger tutorial (Quartz is used by www.cronmaker.com, referenced above), the ? wildcard is only used in the day of month and day of week fields:

根据Quartz CronTrigger教程(Quartz由www.cronmaker.com使用,如上所述),?通配符仅用于星期几和星期几字段:

? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.

? (“无特定值”) - 当您需要在允许该字符的两个字段之一中指定某些内容时有用,而不是另一个字段。例如,如果我希望我的触发器在该月的某个特定日期(例如,第10天)触发,但不关心恰好在一周的哪一天,我会在当天放置“10” -month字段,和“?”在星期几的字段中。

I guess * isn't appropriate here because * means execute on every day of the week, which contradicts the rule saying that it should only run on the 10th of the month.

我想这里*是不合适的,因为*意味着在每周的每一天都执行,这违反了规则,它应该只在该月的10日运行。

#3


-3  

I know it's an old question but for posterity, it's explained here : http://www.nncron.ru/help/EN/working/cron-format.htm#STARTTIME

我知道这是一个古老的问题,但对后代而言,这里有解释:http://www.nncron.ru/help/EN/working/cron-format.htm#STARTTIME

Both in classic and extended modes, nnCron users can use a "nonstandard" character "?" in the first four fields of cron format. It stands for time of nnCron startup, i. e. when a field is processed, startup time will be substituted for the question mark: minutes for Minute field, hour for Hour field, day of the month for Day of month field and month for Month field.

在经典模式和扩展模式下,nnCron用户都可以使用“非标准”字符“?”在cron格式的前四个字段中。它代表nnCron启动的时间,i。即处理字段时,启动时间将替换问号:分钟字段分钟,小时字段小时,月日字段月份日期和月份字段月份。

For example, if you write the following:

例如,如果您编写以下内容:

Time: ? ? * * * * the task will be executed on nnCron startup and then will be executed daily at the same time (unless the user doesn't restart nnCron, of course): question marks will be "replaced" by nnCron startup time. For example, if nnCron was started at 8:25, question marks will be substituted this way:

时间: ? ? * * * *任务将在nnCron启动时执行,然后每天同时执行(当然,除非用户没有重启nnCron):问号将被nnCron启动时间“替换”。例如,如果nnCron在8:25启动,则问号将以这种方式替换:

Time: 25 8 * * * *

时间:25 8 * * * *