CronTrigger

CronTriggers tend to be more useful than SimpleTrigger if you need a calendar-based concept, rather than SimpleTrigger's fully specified time interval, a schedule of recurring launch jobs.
With CronTrigger, you can specify trigger schedules such as "every Friday at noon", or "every weekday at 9:30", or even "every 5 minutes at 9:00 and 10:00 every Monday morning, Wednesday and Friday" .
Even so, like SimpleTrigger, CronTrigger has a startTime that takes effect when the specified schedule, and an (optional) end time when the specified schedule should stop.

Cron Expressions

Cron expressions are used to configure CronTrigger instances. Cron expressions are strings that are actually composed of seven sub-expressions, describing the schedule of individual details. These subexpressions are separated by whitespace and represent:

  1. 1.        Seconds
  2. 2.        Minutes
  3. 3.        Hours
  4. 4.        Day-of-Month
  5. 5.        Month
  6. 6.        Day-of-Week
  7. 7.         Year ( optional field )

Example "0 0 12 ? *WED" is executed every Wednesday at 12:00 PM,

Individual subexpressions can contain ranges, for example, in the previous example ("WED") could be replaced with "MON-FRI", "MON, WED, FRI" or even "MON-WED,SAT".

"*" represents the entire time period.

Each field has a set of valid values ​​that can be specified, such as

Seconds  (seconds): can be represented by numbers 0-59,

Minutes ( minutes): can be represented by numbers 0-59,

Hours ( hours): can be represented by numbers 0-23,

Day-of-Month ( day): You can use any of the numbers 1-31, but pay attention to some special months

Month ( month): can be represented by 0-11 or by the string "JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC"

Day-of-Week ( weekly ) : can be represented by numbers 1-7 (1 = Sunday) or by the string "SUN, MON, TUE, WED, THU, FRI and SAT"

"/": It is a special unit, expressed as "every", such as "0/15", which means every 15 minutes, "0" means starting from "0", "3/20" means every 20 minutes Execute once, "3" means start executing from the 3rd minute

"?": Indicates a certain day of the month, or a certain day of the week

"L": used for monthly, or weekly, expressed as the last day of the month, or the last day of the week of each month, such as "6L" for "the last Friday of the month"

"W": expressed as the most recent working day, for example, "15W" on the day-of-month field is expressed as "the closest working day to the 15th of this month"

""#": is used to specify "" the nth working day of each month. For example, in the field of day-of-week, the content is "6#3" or "FRI#3", which means " 3rd Friday of every month”

 

1) The format of the Cron expression: seconds, minutes, hours, days, months, and years (optional).

               字段名                 允许的值                        允许的特殊字符  
               秒                         0-59                               , - * /  
               分                         0-59                               , - * /  
               小时                     0-23                               , - * /  
               日                         1-31                               , - * ? / L W C  
               月                         1-12 or JAN-DEC         , - * /  
               周几                     1-7 or SUN-SAT           , - * ? / L C #  
               年 (可选字段)     empty, 1970-2099      , - * /

 

               “?”字符:表示不确定的值

               “,”字符:指定数个值

               “-”字符:指定一个值的范围

               “/”字符:指定一个值的增加幅度。n/m表示从n开始,每次增加m

               “L”字符:用在日表示一个月中的最后一天,用在周表示该月最后一个星期X

               “W”字符:指定离给定日期最近的工作日(周一到周五)

               “#”字符:表示该月第几个周X。6#3表示该月第3个周五

 

 

         2)Cron表达式范例:

                 每隔5秒执行一次:*/5 * * * * ?

                 每隔1分钟执行一次:0 */1 * * * ?

                 每天23点执行一次:0 0 23 * * ?

                 每天凌晨1点执行一次:0 0 1 * * ?

                 每月1号凌晨1点执行一次:0 0 1 1 * ?

                 每月最后一天23点执行一次:0 0 23 L * ?

                 每周星期天凌晨1点实行一次:0 0 1 ? * L

                 在26分、29分、33分执行一次:0 26,29,33 * * * ?

                 每天的0点、13点、18点、21点都执行一次:0 0 0,13,18,21 * * ?

转载http://www.cnblogs.com/sunjie9606/archive/2012/03/15/2397626.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326271003&siteId=291194637
Recommended