Cron Expressions
Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that are actually made up of seven sub-expressions, that describe individual details of the schedule. These sub-expression are separated with white-space, and represent:
- Seconds
- Minutes
- Hours
- Day-of-Month
- Month
- Day-of-Week
- Year (optional field)
An example of a complete cron-expression is the string "0 0 12 ? * WED" - which means "every Wednesday at 12:00 pm".
Individual sub-expressions can contain ranges and/or lists. For example, the day of week field in the previous (which reads "WED") example could be replaces with "MON-FRI", "MON, WED, FRI", or even "MON-WED,SAT".
Wild-cards (the '*' character) can be used to say "every" possible value of this field. Therefore the '*' character in the "Month" field of the previous example simply means "every month". A '*' in the Day-Of-Week field would obviously mean "every day of the week".
All of the fields have a set of valid values that can be specified. These values should be fairly obvious - such as the numbers 0 to 59 for seconds and minutes, and the values 0 to 23 for hours. Day-of-Month can be any value 0-31, but you need to be careful about how many days are in a given month! Months can be specified as values between 0 and 11, or by using the strings JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC. Days-of-Week can be specified as vaules between 1 and 7 (1 = Sunday) or by using the strings SUN, MON, TUE, WED, THU, FRI and SAT.
The '/' character can be used to specify increments to values. For example, if you put '0/15' in the Minutes field, it means 'every 15 minutes, starting at minute zero'. If you used '3/20' in the Minutes field, it would mean 'every 20 minutes during the hour, starting at minute three' - or in other words it is the same as specifying '3,23,43' in the Minutes field.
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. See the examples below (and CronTrigger JavaDoc) for clarification.
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" or "FRIL" both mean "the last friday of the month". When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing results.
The 'W' 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".
The '#' is used to specify "the nth" XXX weekday of the month. For example, the value of "6#3" or "FRI#3" in the day-of-week field means "the third Friday of the month".
Here are a few more examples of expressions and their meanings - you can find even more in the JavaDoc for CronTrigger
Example Cron Expressions
CronTrigger Example 1 - an expression to create a trigger that simply fires every 5 minutes
"0 0/5 * * * ?"
CronTrigger Example 2 - an expression to create a trigger that fires every 5 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:05:10 am, etc.).
"10 0/5 * * * ?"
CronTrigger Example 3 - an expression to create a trigger that fires at 10:30, 11:30, 12:30, and 13:30, on every Wednesday and Friday.
"0 30 10-13 ? * WED,FRI"
CronTrigger Example 4 - an expression to create a trigger that fires every half hour between the hours of 8 am and 10 am on the 5th and 20th of every month. Note that the trigger will NOT fire at 10:00 am, just at 8:00, 8:30, 9:00 and 9:30
"0 0/30 8-9 5,20 * ?"
Note that some scheduling requirements are too complicated to express with a single trigger - such as "every 5 minutes between 9:00 am and 10:00 am, and every 20 minutes between 1:00 pm and 10:00 pm". The solution in this scenario is to simply create two triggers, and register both of them to run the same job.
分享到:
相关推荐
`CronTrigger`类就是用来创建基于Cron表达式的触发器,你可以将生成的Cron表达式传递给`CronTrigger`的构造函数来创建触发器。 了解并使用Quartz Cron表达式生成器,可以帮助我们更高效地使用Quartz.NET进行定时...
3. 验证生成的Cron表达式是否符合预期,可以使用Quartz提供的CronTrigger类进行测试和验证。 总之,这个超好用的Quartz Cron表达式HTML工具为Java开发者提供了一个强大的助手,使得管理Quartz定时任务变得更加直观...
通过Job和Trigger接口,开发者可以定义任务的行为和触发条件,然后将其与CronTrigger结合,设置由Cron表达式控制的执行计划。 总的来说,Quartz Cron生成工具是Java开发者必备的辅助工具之一,它能有效提高工作效率...
Quartz Cron JS生成器是一个非常实用的工具,主要用于在JavaScript环境中创建和管理基于Quartz Cron表达式的定时任务。Quartz是Java平台上的一个开源作业调度框架,而Cron表达式则是Unix/Linux系统中用于设置定时...
cmd中运行 ”javar -jar 文件名 “ ,生成可视化窗口,方便 生成和解析Cron;从此怕忘记,再也不求人。
Quartz Cron表达式是Java定时任务库Quartz的重要组成部分,用于定义定时任务的执行规则。Cron表达式是一种字符串格式,由七个子表达式组成,分别代表秒、分、小时、日、月、周和年,允许指定一个精确的时间调度。...
Quartz Cron规则辅助生成工具是一个专门针对Quartz调度库而设计的软件,它的出现极大地帮助了那些需要频繁配置Cron表达式的开发者。作为Java开发者,尤其是那些在大型企业级应用中工作的程序员,他们经常需要设置...
在Quartz中,CronTrigger是最常用的触发器类型,它允许我们使用cron表达式来设置执行时间。cron表达式是一种字符串格式,可以精确地定义任务执行的时间周期。 3. **Scheduler**:Scheduler是Quartz的核心,它负责...
### Quartz Cron表达式详解 #### 一、CronTrigger与SimpleTrigger对比 在Quartz调度器中,`CronTrigger`是一种非常强大的触发机制,它能够根据复杂的日历规则来调度任务,相比于`SimpleTrigger`而言更为灵活。如果...
Quartz Cron表达式生成器是一个基于JavaScript的工具,主要用于帮助前端开发者轻松地创建和理解复杂的Cron表达式。Cron表达式是Unix时间调度的一种格式,广泛应用于各种任务调度系统,包括Java的Quartz框架。它允许...
Cron表达式是Quartz中一个重要的概念,用于定义这些定时任务的执行计划。Cron表达式源自Unix系统的crontab命令,用于配置定时任务,而在Quartz中,它被用来更加灵活地设定作业的触发时间。 标题提到的"quartz的cron...
3. **定义Trigger**:使用CronTrigger类,根据Cron表达式设定触发任务的时间规则。例如,`CronScheduleBuilder.cronSchedule("0 0 12 * * ? *")`创建了一个每天中午12点触发的Trigger。 4. **调度Job**:在...
CRON表达式是Unix cron服务的一种时间格式,也被Quartz所支持。它由六个或七个字段组成,每个字段代表不同的时间单位(秒、分钟、小时、日期、月份、星期、年份),用以描述特定的执行时刻或周期。 这个"quartz 的...
### quartz的cron表达式知识点详解 #### 一、cron表达式概述 cron表达式是一种用于配置定时任务执行规则的语言,广泛应用于Quartz等调度框架中。通过cron表达式,我们可以非常灵活地定义任务的执行时间,包括精确到...
在Quartz中,Cron表达式是一种强大的工具,用于定义作业的触发时间。本文将深入探讨Quartz Cron表达式的实例及其源码解析。 一、Cron表达式基础 Cron表达式是由7个子表达式组成的字符串,每个子表达式代表一个时间...
在Quartz中,我们可以使用`CronTrigger`类来创建基于cron表达式的触发器,并将其与作业(Job)关联,从而定义定时任务。`CronTrigger`的构造函数通常接受cron表达式字符串作为参数。 在实际应用中,理解并熟练掌握...
初学之家(http://www.g2room.com)Cron表达式在线生成器,可方便快捷的生成quartz的cron表达式,及对cron表达式进行解析,提供把Quartz的cron表达式解析执行,展示前10次执行时间。
本文将深入探讨如何使用Quartz配合cron表达式来实现定时任务的实例。 首先,我们要理解cron表达式。Cron表达式是Unix系统中的定时任务调度工具,也被Quartz框架所采用。它由六个或七个子表达式组成,每个子表达式...
Quartz是一款广泛应用于Java环境下的开源任务调度框架,它提供了高度灵活的任务调度机制,使得开发者可以轻松地在应用程序中安排任务的执行。本教程将详细讲解如何使用Quartz实现一个简单的定时器功能。 首先,我们...