Java cron中问号的意义 [英] Significance of question mark in Java cron
问题描述
来源维基百科:
问号 (?) 代替*"用于将月中的某天或一周中的某天留空.
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.
那么,如果我将一些 cron 写为 0 0 0 ?* *
那么是每个月的第一天还是每天执行一次?
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?
这有点令人困惑,因为 Java cron 以秒开头,而其他 cron 以分钟开头.
It is a bit confusing as Java crons start with seconds while other crons start with minute.
推荐答案
根据Quartz CronTrigger 教程(Quartz 是 www.cronmaker.com 使用的,上面有引用),?
通配符只用于月份的哪一天和哪一天周字段:
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:
?(无特定值") - 当您需要在允许字符的两个字段之一中指定某些内容时很有用,而另一个字段则不允许.例如,如果我希望我的触发器在一个月的某一天(比如 10 号)触发,但不关心那一天是一周中的哪一天,我会将10"放在当天-month 字段和?"在星期字段中.
? ("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 日运行的规则相矛盾月.
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.
这篇关于Java cron中问号的意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!