简体   繁体   English

为什么Quartz说这个cron表达式无效?

[英]Why Quartz says this cron expression is not valid?

Quartz 2.x documentation says Quartz 2.x 文档

So cron expressions can be as simple as this: * * * * ? 所以cron表达式可以这么简单:* * * *? * or more complex, like this: 0/5 14,18,3-39,52 * ? *或更复杂,如:0/5 14,18,3-39,52 *? JAN,MAR,SEP MON-FRI 2002-2010 JAN,MAR,SEP MON-FRI 2002-2010

But if I try 但是,如果我尝试

System.out.println(org.quartz.CronExpression.isValidExpression("* * * * ? * *"));

It says 它说

false

Why? 为什么?

Javadoc for the isValidExpression is http://quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html isValidExpression的Javadoc是http://quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html

Ps. PS。 this question is NOT a duplicate of Verifying a cron expression is valid in Java 这个问题不是重复验证cron表达式在Java中是否有效

The linked JavaDoc mentions this structure for cron expressions: 链接的JavaDoc为cron表达式提到了这个结构:

Field Name      Allowed Values       Allowed Special Characters

Seconds         0-59                 , - * /
Minutes         0-59                 , - * /
Hours           0-23                 , - * /
Day-of-month    1-31                 , - * ? / L W
Month           1-12 or JAN-DEC      , - * /
Day-of-Week     1-7 or SUN-SAT       , - * ? / L #
Year (Optional) empty, 1970-2199     , - * /

Your cron expression is "* * * * ? * *" with a ? 你的cron表达式是"* * * * ? * *" ,带有? on the 5th position for Month . 在第5个Month位置。 As you can see, this character is not allowed there. 正如你所看到的,这种性格是不允许存在。

The JavaDoc you mentioned states that the ? 你提到的JavaDoc说明了? character is allowed only for day-of-month and day-of-week fields. 字符仅允许用于日期星期几字段。 You are using it in Month field. 您在Month字段中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM