cron expression interpreter

cron expression by specific rules specified time for regular tasks, simply record some of its syntax and examples, not entirely, to cover most of their daily needs.

1. The overall structure

cron expression is a string, divided into six or seven fields, each separated by a space between two domains, which syntax is:

'S domain and domain-day time-domain domain domain week of May domain domain "

Among them, the domain can be omitted, represent a year when omitted.

2. The meaning of each field

Precautions:

  Each domain numbers, but can also appear as special characters, their meanings are:

  (1) *: indicates matches any value of the field. If you use a domain in Minutes *, it means that every minute a trigger event.

  (2) can only be used ?: DayofMonth and DayofWeek two domains. It also matches any value of the field, but actually not. Because DayofMonth and DayofWeek affect each other. For example, you want to trigger scheduled on the 20th of each month, regardless of the 20 in the end of the week, you can only use the following wording:? 13,131,520 *, which can only be the last one? , * Can not be used, no matter if you use * Indicates day of the week will be triggered, in fact not the case.

  (3) -: indicates a range. 5-20 Minutes domain using, for example, represents from 5 minutes assigned triggered once every 20 minutes

  (4) /: indicating a start time of a start trigger, and a trigger every predetermined time. For example, in the domain 5/20 Minutes, it means five minutes once triggered, 25, 45, respectively, while the trigger once.

  (5) ,: listed represent the enumeration values. For example: the use of 5,20 in Minutes field, it means that the trigger once per minute at 5 and 20 minutes.

  (6) L: represents the last, and only appeared in DayofWeek DayofMonth domain. If you use 5L in DayofWeek domain, meaning that triggered last Thursday.

  (7) W: represents the effective working days (Monday to Friday), can only appear in DayofMonth domain, the system will trigger events in recent days from the effective date specified. For example: the use of 5W in DayofMonth, if the 5th is a Saturday, then in recent days: Friday that the 4th trigger. If the 5th is a Sunday, then on the 6th (Zhouyi) is triggered; if, in the Friday day, it triggers on Monday 5th in the 5th. Another point, W recently looking for does not cross the month.

  (8) LW: These two characters can be used in conjunction, represent the last working day in a month, and last Friday.

  (9) #: means for determining a month the first few days of the week, only appear in DayofWeek domain. For example, in 4 # 2, it represents the second Wednesday of the month.

  Third, the common expression examples

  (0) 0/20 * * * *? Represents a tuning tasks every 20 seconds

  (1) 0021 *? Represents a tuning task of every month 2:01 Day

  (2) 0 15 10? * MON-FRI said on Monday through Friday at 10:15 am every day to perform the job

  ? (3) 0 15 10 6L 2002-2006 represents 2002-- last Friday at 10:15 am for the implementation of the 2006 monthly

  (4) 00 10,14,16 * *? 10:00 every day, 14:00, 4:00

  (5) * * 0 0/30 9-17? Inward nine to five hours every half hour

  (6) 0 0 12? * WED represent every Wednesday 12:00

  (7) 0012 * *? 12:00 every day trigger

  (8) 01 510? * * Trigger every day at 10:15 am

  (9) 01510 * *? Triggered daily at 10:15 am

  (10) 01510 * *? * Trigger every day at 10:15 am

  (11) 01510 * *? 2005 2005 at 10:15 am every day trigger

  (12) 0 14 * * *? Triggered during every minute of every day at 2:00 pm to 2:59 pm

  (13) 0/5 0 14 * *? During 2:00 pm to 2:55 pm each day of the trigger every 5 minutes

  Every 5 minutes trigger (14) 0/5 0 * 14, 18 *? And 6:00 pm to 6:55 during the period of 2:00 to 2:55 every afternoon

  (15) 00-514 * *? During 2:00 pm to 2:05 pm every day of every 1 minute when the

  (16) 0 10,44 14? ​​3 WED Wednesday of March each year 2:10 pm and 2:44 trigger

  (17) 0 15 10? * MON-FRI 10:15 am Monday through Friday, triggering

  (18) 0151015 *? Trigger 15th of each month at 10:15 am

  (19) 0 15 10 L *? 10:15 am on the last day of each month triggered

  (20) 0 15 10? * 6L last Friday of each month at 10:15 am triggering

  (21) 0 15 10? * 6L 2002-2005 2002 to 2005 years last Friday of each month at 10:15 am triggering

  (22) 01 510? * 6 # 3 the third Friday of each month at 10:15 am triggering

 

  Note:

       1. Some sub-expressions can contain a range or list
   such as: sub-expressions (days (weeks)) can be "MON-FRI", "MON , WED, FRI", "MON-WED, SAT"

        2. "*" character represents all possible values, so the "*" indicates the meaning of each month in the sub-expression (month), the "*" in the sub-expression (days (weeks)) represent each day of the week

  3. "/" character is used to increment a specified value
   , for example: in the subexpression (minutes) in the "0/15" indicates the start 0 minute, every 15 minutes
         in the sub-expression (minutes) in the "3 / 20 "from the first three minutes, every 20 minutes (it" 3,23,43 ") as meaning

  4. The "?" Character is used only day (month) and day (week) two sub-expression that do not specify a value
   when one of the two sub-expressions which are assigned a value in the future, in order to avoid conflict, need another subexpression is set to "?"

  5. "L" character is used only day (month) and day (week) two sub-expressions, which is an abbreviation of the word "last", but its meaning in the two sub-expressions is different.
   Day (month) sub-expression, "L" represents the last day of the month
   in the day (week) from the expression, "L" represents the last day of the week, which is the SAT, if there is at "L" before specific content, it has other meanings of the
   example: "6L" the reciprocal of the sixth day of the month, "FRIL" represents the best Friday of the month. Note: When using the "L" parameter, do not specify the list or range, as this can cause problems

 

Guess you like

Origin www.cnblogs.com/unknows/p/12608090.html