Cron expressions are used to configure instances of CronTrigger, a subclass of org.quartz.Trigger. A cron expression is a string consisting of six or seven subexpressions (fields) that describe individual details of the schedule.
These fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field. Table A-1 shows the fields in the expected order.
Table A-1 Cron Expressions Allowed Fields and Values
Seconds |
Y |
0-59 |
, - * / |
Minutes |
Y |
0-59 |
, - * / |
Hours |
Y |
0-23 |
, - * / |
Day of month |
Y |
1-31 |
, - * ? / L W C |
Month |
Y |
0-11 or JAN-DEC |
, - * / |
Day of week |
Y |
1-7 or SUN-SAT |
, - * ? / L C # |
Year |
N |
empty or 1970-2099 |
, - * / |
Example A-1 Cron Expressions
Cron expressions can be as simple as * * * * ? *
or as complex as 0 0/5 14,18,3-39,52 ? JAN,MAR,SEP MON-FRI 2002-2010
.
The '*' character is used to specify all values. For example, "*" in the minute field means "every minute".
The '?' character is allowed for the day-of-month and day-of-week fields. It is used to specify 'no specific value'. This is useful when you need to specify something in one of the two fields, but not the other.
The '-' character is used to specify ranges For example "10-12" in the hour field means "the hours 10, 11 and 12".
The ',' character is used to specify additional values. For example "MON,WED,FRI" in the day-of-week field means "the days Monday, Wednesday, and Friday".
The '/' character is used to specify increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying '*' before the '/' is equivalent to specifying 0 is the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The "/" character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does NOT mean every 6th month, please note that subtlety.
The 'L' character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value "L" in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means "7" or "SAT". But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example "6L" means "the last friday of the month". You can also specify an offset from the last day of the month, such as "L-3" which would mean the third-to-last day of the calendar month. When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing/unexpected results.
The 'W' character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify "1W" as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary of a month's days. The 'W' character can only be specified when the day-of-month is a single day, not a range or list of days.
The 'L' and 'W' characters can also be combined for the day-of-month expression to yield 'LW', which translates to "last weekday of the month".
The '#' character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and "#3" = the 3rd one in the month). Other examples: "2#1" = the first Monday of the month and "4#5" = the fifth Wednesday of the month. Note that if you specify "#5" and there is not 5 of the given day-of-week in the month, then no firing will occur that month. If the '#' character is used, there can only be one expression in the day-of-week field ("3#1,6#3" is not valid, since there are two expressions).
The legal characters and the names of months and days of the week are not case sensitive.
NOTES:
- Support for specifying both a day-of-week and a day-of-month value is not complete (you'll need to use the '?' character in one of these fields).
- Overflowing ranges is supported - that is, having a larger number on the left hand side than the right. You might do 22-2 to catch 10 o'clock at night until 2 o'clock in the morning, or you might have NOV-FEB. It is very important to note that overuse of overflowing ranges creates ranges that don't make sense and no effort has been made to determine which interpretation CronExpression chooses. An example would be "0 0 14-6 ? * FRI-MON".
相关推荐
这篇名为"Cron expression 校验 js版本"的博客文章可能详细介绍了如何用JavaScript编写一个Cron表达式校验函数。作者可能分享了如何将Cron字符串分解为各个部分,逐一检查每个部分的合法性,以及如何处理特殊情况,...
在`mtdowling-cron-expression-3cc89f5`这个压缩包中,包含了CronExpression库的源代码。开发者可以通过阅读源代码,了解其实现细节和内部结构。这个版本可能包含了类定义、方法实现、单元测试等部分,有助于深入...
Cron Expression UI :输入组件,可轻松直观地生成cron表达式,如 例子 使用说明 NPM 从安装软件包 npm install cron-expression-input@1.2.7 在你的代码中 import "cron-expression-input/lib/cron-expression-...
console.log('Cron expression changed:', newCron); // 在这里处理Cron表达式的变更 } } }; ``` 以上代码展示了如何在Vue组件中引入Vue-Cron,通过`v-model`双向绑定Cron表达式,并监听`@change`事件来响应...
在Quartz中,`cronExpression`是用于设置基于cron表达式的时间触发规则的关键配置项,这种表达式允许我们以非常灵活的方式定义任务的执行周期。 cronExpression的格式是由7个子表达式组成的字符串,每个子表达式...
安装将 CronExpressionGenerator 库添加到您的composer.json文件中: composer require swekaj/cron-expression-generator用法要将其与一起使用,您必须将CronExpressionGenerator\FakerProvider类添加到 Faker 生成...
cron-expression-1.0.zip是一个包含cron表达式相关工具的压缩包,主要提供Web版和EXE版本。cron表达式是Unix和Linux操作系统中的时间调度语法,广泛应用于自动化任务的计划,例如定时执行脚本或任务。这个工具可能是...
cron是Unix/Linux操作系统中的一个调度任务工具,用于设置周期性被执行的任务。它的名称来源于古英语单词"crone",象征时间的流转。在JavaScript中,我们可以利用类似cron的表达式来实现定时任务,例如通过`jquery-...
在用户设置了时间规则后,我们需要将其转换为 Unix Cron Expression,以便于 Quartz 任务调度器可以正确地解析和执行任务。我们可以使用 Quartz 提供的 CronExpression 类来实现时间规则的解析和转换。 3. 将转换后...
这类实体类通常会包含一些属性,如`expression`(Cron表达式字符串)、`nextExecutionTime`(下一个执行时间)等,以及相应的getter和setter方法。 3. **CronExpParserUtil.java**:这是一个工具类,很可能提供了...
其中,cron表达式(cron expression)是用于定义任务执行时间的一种方式,在Spring与Quartz的结合中发挥着重要作用。 #### cron表达式的格式 cron表达式由六个或七个子表达式组成,这些子表达式分别代表: 1. **...
- **Cron Expression验证**:确保输入的Cron表达式符合规范,能正确触发任务执行。 3. **关键技术** - **JMX API**:是Java平台的核心组件之一,用于管理和监控Java应用程序,它提供了暴露管理接口的标准方式,使...
Cron表达式解析器该实用程序使用户能够以标准格式(Example: */15 0 1,15 * 1-5 /usr/bin/find)将cron expression + command的组合cron expression + command传入参数,并以爆炸格式输出输出,如下所示:如下: ...
cron_expression-master.zip是一个包含C++库的压缩包,主要用于处理Linux系统中的crontab配置串。crontab是一个Unix及类Unix系统中的时间计划任务工具,允许用户设置定时执行的任务。其配置串采用了一种特殊的格式,...
您可以使用PHP Cron Expression Parser。注意:该分叉已被弃用,开发移至https://github.com/dragonmantank/cron-expression。 可以在此处的博客文章中找到更多信息。 tl; dr-v2.0.0是一个重大的重大更改,@ ...
Cron表达描述符 将 cron 表达式转换为人类可读描述的 .NET 库。 作者:Brady Holt ( )许可证: 特征 支持所有 cron 表达式特殊字符,包括 * / , - ? 体重,# 支持5、6(w /秒或年)或7(w /秒和年)部分cron表达式...
克隆表达式,即Cron Expression,是Quartz中用于定义任务执行时间的关键概念,它允许开发者精确地控制任务的触发时机。Cron表达式由七个字段组成,分别对应不同的时间单位: 1. 秒(0~59):定义任务在每一分钟内的...
console.log("Cron expression updated:", cronExpression); }); ``` ### 4. Cron表达式基础 Cron表达式由5到6个(或7个,包含年份)空格分隔的字段组成,每个字段代表不同的时间单位:秒、分钟、小时、日期、...
System.out.println("This task is executed every 5 minutes using Cron expression."); } } ``` 多线程在定时任务中的运用主要体现在,当有多个定时任务需要并发执行时,通过开启多个线程可以避免任务之间的...
文件"expression"可能是源代码或者测试数据,包含了实现上述功能的具体Java代码。如果要深入学习或修改这个项目,你需要查看代码来了解它的实现细节,包括如何处理用户输入、如何解析和验证Cron表达式,以及如何在...