QuartZ Cron Expressions

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 the startTime specified when the schedule takes effect, and the specified schedule should stop at the (optional) end time.

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" means to execute every 15 minutes, "0" means to start from "0" minutes, "3/20" means to mean 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).

               Field Name Allowed Values ​​Allowed Special Characters  
               Seconds 0-59 , -*/  
               Minutes 0-59 , -*/  
               hours 0-23 , -*/  
               Days 1-31 , -* ?/LWC  
               Months 1-12 or JAN- DEC , -*/  
               day of the week 1-7 or SUN-SAT , -* ?/LC  
               #year (optional field) empty, 1970-2099 , -*/

 

               "?" character: Indicates an indeterminate value

               "," character: specify several values

               "-" character: specifies a range of values

               "/" character: Specifies the increment of a value. n/m means starting from n and increasing m each time

               "L" character: used in day to indicate the last day of the month, used in week to indicate the last week of the month X

               "W" character: Specifies the working day closest to the given date (Monday to Friday)

               "#" character: Indicates the week X of the month. 6#3 means the 3rd Friday of the month

 

 

         2) Cron expression example:

                 Execute every 5 seconds: */5 * * * * ?

                 Execute every 1 minute: 0 */1 * * * ?

                 Execute once a day at 23:00: 0 0 23 * * ?

                 Execute once a day at 1 am: 0 0 1 * * ?

                 Execute once every month at 1:00 am: 0 0 1 1 * ?

                 Executed at 23:00 on the last day of every month: 0 0 23 L * ?

                 Executed once a week at 1 am on Sunday: 0 0 1 ? *L

                 Execute once at 26, 29, 33: 0 26,29,33 * * * ?

                 Execute once every day at 0:00, 13:00, 18:00, and 21:00: 0 0 0,13,18,21 * * ?

 

Reprinted from: http://www.cnblogs.com/sunjie9606/archive/2012/03/15/2397626.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326963357&siteId=291194637