cron expr

api docs说的很清楚,不需要去搜索,

org.quartz
类 CronExpression

java.lang.Object
  

org.quartz.CronExpression
所有已实现的接口:
java.io.Serializable, java.lang.Cloneable

public class CronExpressionextends java.lang.Objectimplements java.io.Serializable, java.lang.Cloneable

Provides a parser and evaluator for unix-like cron expressions. Cron expressions provide the ability to specify complex time combinations such as "At 8:00am every Monday through Friday" or "At 1:30am every last Friday of the month".

Cron expressions are comprised of 6 required fields and one optional field separated by white space. The fields respectively are described as follows:

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   , - * /

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". When using the ‘L‘ option, it is important not to specify lists, or ranges of values, as you‘ll get confusing 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".
作者:
Sharada Jambula, James House, Contributions from Mads Henderson, Refactoring from CronTrigger to CronExpression by Aaron Craven
另请参见:
序列化表格

构造方法摘要
CronExpression(java.lang.String cronExpression)
          Constructs a new CronExpression based on the specified
parameter.

cron expr

时间: 2024-10-20 13:06:28

cron expr的相关文章

Go cron定时任务的用法

cron是什么 cron的意思就是:计划任务,说白了就是定时任务.我和系统约个时间,你在几点几分几秒或者每隔几分钟跑一个任务(job),就那么简单. cron表达式 cron表达式是一个好东西,这个东西不仅Java的quartZ能用到,Go语言中也可以用到.我没有用过Linux的cron,但网上说Linux也是可以用crontab -e 命令来配置定时任务.Go语言和Java中都是可以精确到秒的,但是Linux中不行. cron表达式代表一个时间的集合,使用6个空格分隔的字段表示: 字段名 是否

task:scheduled cron 合法

task:scheduled org.springframework.scheduling.support.CronSequenceGenerator.parse /** * Parse the given pattern expression. */ private void parse(String expression) throws IllegalArgumentException { String[] fields = StringUtils.tokenizeToStringArray

go任务调度2(linux的cron调用)

cron格式:分 时 日 月 周 每隔5分钟执行1次: /5 * echo hello > /tmp/x.log 每隔1-5分钟执行1次: 1-5 echo hello > /tmp/x.log 每天10点整.22点整执行1次: 0 10,22 * echo hello > /tmp/x.log 每隔1-5分钟执行1次: 1-5 echo hello > /tmp/x.log Parse():解析与校验Cron表达式Next():根据当前时间,计算下次调度时间 package ma

六、任务计划管理cron

6.1.一次任务计划at/batch at:定时运行命令 作用:at命令再指定时刻执行指定的命令序列 用法:at [-V][-q 队列][-f file][-m] time 常用选项: -V:输出版本号 -q:选用-q参数则可选队列名称,队列名称可以是a-z和A-Z之间的字母,队列字母顺序越高,队列优先级越高. -f:从文件中读取命令或者shell脚本,而非在提示后指定他们. -m:执行完作业后发送邮件给用户 time:指定作业执行时间    绝对时间: HH:MM, DD.MM.YY MM/D

centos 下的任务计划 -- cron

cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: /sbin/service crond start //启动服务 /sbin/service crond stop //关闭服务 /sbin/service crond restart //重启服务 /sbin/service crond reload //重新载入配置 1.crontab命令选项: -u指定一个用户, -l列出

at、cron周期性任务计划详解

一.一次性任务计划:at.batch 1.batch:系统自行选择在系统资源较空闲的时间去执行指定的任务 用法类似于at,但只要提交所需执行的命令 2.at:指定未来的某时间点执行一次某任务 (1)用法格式:at   [OPTION]...   TIME 1)TIME格式: HH:MM [YYYY-mm-dd]:直接指明具体的时间 noon,midnight, teatime:中午.午夜.下午茶时间(下午四点左右) tomorrow:明天 now+#:现在之后的多久,可使用表示单位为minute

cron表达式的解释

cron表达式是什么 首先cron是表示计划任务.其次Oracle官网这样解释cron表达式: 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 individu

计划任务 at   batch   cron anacron

在使用Linux的过程中,我们有时需要使用一些定时任务的功能,Linux上常用的计划任务工具有at.batch和cron.anacron,下面我就来简单的说一说. at:仅执行一次就从Linux的计划任务中取消 batch:系统有空就执行 cron:周期性执行 anacron:唤醒停机期间的工作任务 (一).at (*依赖于atd服务,需先手动安装 *) [[email protected] ~]# yum -y install at [[email protected] ~]# systemc

let 与 expr Shell运算比较 let强强胜出

Shell脚本中 整数运算一般通过 let 和 expr 这两个指令来实现,如对变量 s 加 1 可以写作:let "s = $s + 1" 或者 s=`expr $s + 1'两者的写法没都很简单,但是性能的比较可以来实例给大家演示一下: 1.expr脚本与执行时间: #!/bin/bash s=0 while [ $s -lt 10000 ] do s=`expr $s + 1` echo $s >>/dev/null 2>&1 done [[email