- 浏览: 127451 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
ZhaojieSmall:
www.baidu.com
Drools 5 模板技术应用(drools template) -
ZhaojieSmall:
...
Spring注解jar包中的类的问题 -
zoutuo:
其实不需要注销重启,执行 source /etc/profil ...
MAVEN_HOME的设置 -
duyangsss:
有可能是网络问题吗?你是否能通过IE在code.google上 ...
SVN之无法连接到服务器 -
localtest:
我在访问Googl SVN的时候也出现你这种情况,前天晚上还好 ...
SVN之无法连接到服务器
Cron 表达式格式
Quartz的cron表达式与UNIX的cron表达式很相似,只有在个别地方有一些细微区别。
其中一个不同就是Quartz所提供的表达式精确到秒,而UNIX的cron表达式只提供分钟的精度设置。因为当我们使用Quartz执行计划任务经常会使用到秒级别(如:每45秒执行某一个任务一次),因此就是这些不同。
使用UNIX中,某一个工作将被一个所储存的cron表达式所触发执行,这个表达式需要设置六个位置。
With UNIX cron, the job (or command) that is to be executed is stored with the cron expression, in the sixth position. Quartz uses the cron expression to store the firing schedule. The CronTrigger, which references the cron expression, is associated with the job at schedule time.
Another difference between the UNIX cron expression format and Quartz is the number of supported fields in the expression. Where UNIX gives five (minute, hour, day, month, and dayofweek), Quartz provides seven. Table 5.1 lists the seven cron expression fields Quartz supports.
Seconds |
Yes |
059 |
, - * / |
Minutes |
Yes |
059 |
, - * / |
Hours |
Yes |
23 |
, - * / |
Day of Month |
Yes |
131 |
, - * ? / L W C |
Month |
Yes |
112 or JAN-DEC |
, - * / |
Day of Week |
Yes |
17 or SUN-SAT |
, - * ? / L C # |
Year |
No |
Blank or 19702099 |
, - * / |
The names of months and days of the week are not case sensitive. FRI is the same as fri. |
The fields are separated by a space, just as with UNIX cron. Arguably, the simplest expression we could write would look something like this:
* * * ? * *
This expression would fire the scheduled job every second, for every minute, for every hour of every day.
Understanding the Special Characters
As with UNIX cron, Quartz cron expressions support special characters that can be used to create more complicated execution schedules. However, Quartz supports many more than the standard UNIX cron expression.
The * Character
Using the asterisk (*) in a field indicates that you want to include all legal values for that field. For example, using this character in the month field means to fire the trigger for every month.
Example expression:
0 * 17 * * ?
Meaning: Fire the trigger every minute, every day starting at 5 PM until 5:59 PM. It stops at 5:59 PM because the value 17 is in the hour field, and at 6 PM, the hour becomes 18 and doesn't agree with this trigger until the next day at 5 PM.
Use the * character when you want the trigger to fire for every valid value of the field.
The ? Character
The question mark (?) character can be used only in the dayofmonth and dayofweek fields, but not at the same time. You can think of the ? character as "I don't care what value is in this field." This is different from the asterisk, which indicates every value for the field. The ? character says that no value was specified for this field.
The reasons a value can't be specified for both fields are tough to explain and even tougher to understand. Basically, if a value was specified for each, the meaning would become ambiguous: Consider if an expression had the value 11 in a field for the day of the month and a value of WED in the field for the day of the week. Should that trigger fire only on the 11th of the month if it falls on a Wednesday? Or should it fire on both the 11th and every Wednesday? The ambiguity is removed by not allowing a value in both fields at the same time.
Just remember that if you specify a value in one of the two fields, you must put a ? in the other.
Example expression:
0 10,44 14 ? 3 WED
Meaning: Fire at 2:10 PM and 2:44 PM every Wednesday in the month of March.
The , Character
The comma (,) character is used to specify a list of additional values within a given field. For example, using the value 0,15,30,45 in the second field means to fire the trigger every 15 seconds.
Example expression:
0 0,15,30,45 * * * ?
Meaning: Fire the trigger on every quarter-hour.
The / Character
The slash (/) character is used to schedule increments. We just used the comma to increment every 15 minutes, but we could have also written it like 0/15.
Example expression:
0/15 0/30 * * * ?
Meaning: Fire the trigger every 15 seconds on the hour and half-hour.
You can't increment beyond the fields range. For example, you can't specify 30/20 in the second field and expect the scheduler to fire correctly.
The Character
The hyphen (-) character is used to specify a range. For example, 3-8 in the hour field means "the hours 3, 4, 5, 6, 7, and 8." The fields will not wrap, so values such as 50-10 are not allowed.
Example expression:
0 45 3-8 ? * *
Meaning: Fire the trigger on 45 past the hours 3 AM through 8 AM.
The L Character
The L character represents the last allowed value for the field. It is supported by the dayofmonth and dayofweek fields only. When used in the dayofmonth field, it represents the last day of the month for the value specified in the month field. For example, when the month field has JAN specified, using L in the dayofmonth field would cause the trigger to fire on January 31. If SEP was specified as the month, then L would mean to fire on September 30. In order words, it means to fire the trigger on the last day of whatever month is specified.
The expression 0 0 8 L * ? means to fire the trigger at 8:00 AM the last day of every month. The * character in the month field gives us the "every month" part.
When the L character is used in the dayofweek field, it indicates the last day of the week, which is Saturday (or, numerically, 7). So if you needed to fire the trigger on the last Saturday of every month at 11:59 PM, you could use the expression 0 59 23 ? * L.
When used in the dayofweek field, you can use a numerical value in conjunction with the L character to represent the last X day of the month. For example, the expression 0 0 12 ? * 2L says to fire the trigger on the last Monday of every month.
The W Character
The W character stands for weekday (MonFri) and can be used only in the dayofmonth field. It is used to specify the weekday that is nearest to the given day. Most business processes are based on the work week, so the W character can be very important. For example, a value of 15W in the dayofmonth field means "the nearest weekday to the 15th of the month." If the 15th was on a Saturday, the trigger would fire on Friday the 14th because it's closer to the 15th than Monday, which would be the 17th in this example. The W character can be specified only when the day of the month is a single day, not a range or list of days.
The # Character
The # character can be used only in the dayofweek field. It's used to specify the nth XXX day of the month. For example, if you specified the value 6#3 in the dayofweek field, it would mean the third Friday of the month (6 = Friday and #3 means the third one in the month). Another example of 2#1 means the first Monday of the month (2 = Monday and #1 means the first one of the month). Note that if you specify #5 and there is no 5 of the given day of the week in the month, no firing will occur that month.
发表评论
-
https://www.aiplan365.com
2019-10-23 11:40 0https://www.aiplan365.com -
Mysqlbinlog使用
2014-07-04 01:10 10591、binlog 基本认识 MySQL ... -
MYSQL ERROR CODE 翻译
2014-06-18 14:56 877mysql error code(备忘) 转10 ... -
从Maven仓库中导出jar包
2014-01-29 11:35 944从Maven仓库中导出jar包:进入工程pom.xml 所在的 ... -
Guvnor源码解析-专业术语说明
2014-01-29 10:22 918Category类别,对知识库或资产进行分类,方便查询Moud ... -
Guvnor源码解析-Jackrabbit自定义结点类型
2014-01-29 00:38 1048在Guvnor的guvnor-repository的src/m ... -
Websphere中静态资源的过虑
2012-11-15 15:37 3440公司有一个B/S的项目,其中视图层是使用JSP+JA ... -
spring工程JBoss移植的hibernate异常
2012-09-18 14:11 2645之前在tomcat7中开发了一个spring的web工程,其中 ... -
在EJB中执行CREATE SEQUENCE
2012-08-31 13:04 2062一个业务需求,需要在EJB服务中执行DDL语句创建序列号: ... -
Office文档转pdf
2012-03-28 21:54 1403由于某个项目的原因,需要将微软的文档,如:xls,doc,do ... -
SVN之无法连接到服务器
2012-01-30 23:25 8215当我在VPS中安装了一个SVN的服务器,并且将svn与ap ... -
Spring注解jar包中的类的问题
2011-12-08 19:06 5512在每一个SSH项目中,都会为持久层操作封装一套持久化操作接口, ... -
关于spring中配置hibernate申明事务无效的问题
2011-12-08 17:05 2529在spring配置hibernate的申明事务的时候,发现事务 ... -
Eclipse常用插件安装指南
2011-11-18 23:12 888插件名称下载地址说明Properties Editorhttp ... -
使用数据库字典
2011-07-28 09:46 910简单数据库字典使用 SELECT T.table_name ... -
Oracle 创建 schema
2011-05-07 10:03 1130开始不是很明白,最近才搞清楚。schema就是一些数 ... -
关于svn的添加忽略
2011-05-06 12:58 3331当我们在使用svn对代码进行管理的时候,往往有一些目录或 ... -
J2EE中多模块的项目工程问题
2011-02-19 12:43 1350在一个J2EE中,当项目的主要业务逻辑要划分为多个模块时(及 ... -
JPA的实体关联中cascade的使用
2011-02-18 15:31 3496在一对多关联关系中什么时候应该使用级联的方式呢? 其实 ...
相关推荐
### cron表达式详解 cron表达式是用于定义定时任务执行时间的一种格式,广泛应用于Linux系统中的计划任务。本文将深入解读cron表达式的各个组成部分及其使用方法。 #### cron表达式的基本结构 一个完整的cron...
CRON表达式是一种用于在Unix和Linux系统以及许多其他支持它的平台上设置定时任务的强大工具。它基于一组预定义的规则,用字符串的形式来表达时间的周期性安排。这个表达式通常由五个或六个字段组成,有时甚至包括一...
### cron表达式详解 cron表达式是由7个子字段组成的字符串,每个字段代表不同的时间单位,从左到右分别是: 1. **秒(Seconds)**:0-59,可以设置分号(;)进行多个值的分隔。 2. **分钟(Minutes)**:0-59。 3....
### Quartz Cron 表达式详解 #### 一、概述 Quartz是一款强大的开源作业调度框架,广泛应用于Java应用程序中,用于实现定时任务的功能。Quartz支持多种触发器类型,其中最为灵活且功能强大的是CronTrigger,它允许...
### Cron表达式详解 Cron表达式由6或7个子表达式组成,每个子表达式代表不同的时间单位:秒、分钟、小时、日期、月份中的日期、月份和星期几(在某些实现中还包括年份)。这些子表达式通过空格分隔,并可以包含数字...
Quartz 的 cron 表达式详解 Quartz 的 cron 表达式是一个强大的调度工具,用于设置定时任务的执行时间。它由七个字段组成,分别是秒、分钟、小时、天(月)、月、天(星期)和年份。每个字段可以设置特定的值、范围...
本文将深入探讨如何在Spring项目中集成Quartz,并详细解析Cron表达式,以便更好地理解和运用定时任务。 首先,集成Quartz到Spring项目中通常涉及以下步骤: 1. **引入依赖**:在项目的pom.xml或build.gradle文件中...
### Cron表达式详解 #### 一、Cron表达式概述 Cron表达式是一种用于配置定时任务执行时间的标准格式,在很多系统中都有广泛的应用,比如Quartz调度器、Linux操作系统等。通过Cron表达式,我们可以灵活地设定任务...
### Quartz Cron表达式详解 #### 一、CronTrigger与SimpleTrigger对比 在Quartz调度器中,`CronTrigger`是一种非常强大的触发机制,它能够根据复杂的日历规则来调度任务,相比于`SimpleTrigger`而言更为灵活。如果...
**Cron表达式详解** Cron表达式是一种广泛用于任务调度的语法,它允许我们设置时间规则来执行特定的任务。这种表达式源自Unix系统中的cron daemon,现在在各种编程语言和平台中都有应用,包括Java的Quartz框架、...
### cron表达式详解 cron表达式是由7个子表达式组成的字符串,每个子表达式之间用空格分隔,代表不同的时间单位: 1. **秒(Seconds)**:0-59的整数,可包含逗号分隔的多个值或范围。 2. **分钟(Minutes)**:0-...
### Quartz的Cron表达式详解 #### 一、Cron表达式概述 Cron表达式是一种用于配置定时任务执行频率的格式化字符串。在Quartz调度器中,CronTrigger类型的触发器支持Cron表达式来定义触发规则。Cron表达式由六个或七...
Cron表达式详解-附件资源
Cron表达式是一种广泛用于定时任务调度的工具,它基于字符串的形式定义了任务的执行时间。这个表达式由5到6个(有时是7个)空格分隔的字段组成,每个字段代表一个时间维度,从秒到年。具体格式为{秒}{分钟}{小时}{...
Cron表达式详解** Cron表达式由5个或6个字段组成,每个字段代表一个时间维度,从左到右依次是秒、分钟、小时、日期、月份和星期。每个字段可以是一个具体的值,一个范围,一个列表,或者一个通配符(星号*),表示...
【Cron表达式详解】 Cron表达式是一种强大的时间调度机制,广泛应用于各种定时任务的配置,例如在Java中的Quartz框架。它是由七个子表达式组成的字符串,每个子表达式都代表一个时间维度(秒、分钟、小时、日期、...
### quartz的cron表达式知识点详解 #### 一、cron表达式概述 cron表达式是一种用于配置定时任务执行规则的语言,广泛应用于Quartz等调度框架中。通过cron表达式,我们可以非常灵活地定义任务的执行时间,包括精确到...
CRON表达式详解 CRON表达式由六个或七个字段组成,每个字段代表不同的时间单位,从左到右依次为: - 秒(0-59) - 分钟(0-59) - 小时(0-23) - 日(1-31) - 月份中的月日(1-31) - 月份(1-12) - 星期(0-7,...
**cron表达式详解:** cron表达式由一系列由空格分隔的字段组成,每个字段代表不同的时间单位。例如,`* * * * * *` 表示每秒执行一次。每个字段可以是单个数值、范围(如1-5)、列表(1,3,5)或者通配符(*,代表...