QuartZ extension-Cron expression

If you need to trigger tasks on a schedule like a calendar, instead of triggering at specific intervals like SimpleTrigger, CronTriggers are usually more useful than SimpleTrigger.

Using CronTrigger, you can specify items such as "Every Friday at noon", or "Every weekday at 9:30" or "Every Monday, Wednesday, Friday from 9:00 am to 10:00 am This is triggered by the schedule every five minutes. Even, like SimpleTrigger, CronTrigger also has a StartTime to specify when the schedule starts, and an (optional) EndTime to specify when the schedule does not continue.

Cron Expressions-Cron expressions

Cron expressions are used to configure CronTrigger instances. Cron expression is a string consisting of 7 sub-expressions. Each sub-expression describes a separate schedule detail. These sub-expressions are separated by spaces and represent:
  1. Seconds

  2. Minutes

  3. Hours

  4. Day-of-Month

  5. Month

  6. Day-of-Week

  7. Year (optional field) Year (optional field)

An example string of cron expression is "0 0 12? * WED", which means "12:00 noon every Wednesday".

A single subexpression can contain ranges or lists. For example: the day of the week in the previous example (here "WED") can be replaced with "MON-FRI", "MON, WED, FRI" or even "MON-WED, SAT".

Wildcards ('*') can be used to represent "every" possible value in the domain. Therefore, the * in the "Month" field means every month, and the * in the Day-Of-Week field means "every day of the week".

The values ​​in all fields have specific legal ranges. The legal ranges of these values ​​are quite obvious. For example, the legal values ​​for seconds and minutes are from 0 to 59, and the legal range for hours is from 0 to 23. Day-of-Month It is worth the legal range is 0 to 31, but need to pay attention to the number of days in different months. The legal values ​​for the month are 0 to 11. Or use the string JAN, FEB MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV and DEC. Days-of-Week can be represented by 1 to 7 (1=Sunday) or the string SUN, MON, TUE, WED, THU, FRI and SAT.

The'/' character is used to indicate the increment of the value. For example, if you put '0/15' in the minute field, it means "every 15 minutes, starting from 0", if you use '3/20 in the copy field ', it means "every 20 minutes in the hour, starting from the 3rd minute" or otherwise the same form is '3,23,43'.

The'?' character can be used in the day-of-month and day-of-week fields, and it is used to mean "no specified value". This is useful for specifying the value of one or two fields without setting other fields.

The'L' character can be used in day-of-month and day-of-week. This character is short for "last", but has different meanings in the two fields. For example, the "L" in the day-of-month field means the last day of the month, that is, the 31st of January and the 28th of February in a non-leap year. If it is used in day-of-week, it means "7" or "SAT". But if this character is followed by other values ​​in the day-of-week field, it means "the last week of the month XXX". For example: "6L" or "FRIL" both indicate the last Friday of the month. When using the'L' option, the most important thing is not to specify a list or value range, otherwise it will cause confusion.

The'W' character is used to specify the closest week to a given day (specified in the day-of-week field). For example: if you specify "15W" for the day-of-month field, it means "the day of the week closest to the 15th of the month".

'#' indicates the day of the month. For example: "6#3" or "FRI#3" in the day-of-week field means "the third Friday of the month".

Here are some expressions and their meanings.

Example Cron Expressions-Examples of Cron expressions

CronTrigger

Example 1-A simple expression that triggers every 5 minutes

"0 0/5 * * * ?" CronTrigger

 Example 2-An expression that triggers every 5 minutes after 10 seconds of every minute (eg. 10:00:10 am, 10:05:10, etc.).

"10 0/5 * * * ?" CronTrigger

Example 3-An expression to be triggered at 10:30, 11:30, and 12:30 every Wednesday and Friday.

"0 30 10-13 ? * WED,FRI" CronTrigger

Example 4-On the 5th and 20th of each month, it is triggered every half an hour between 8 and 10 o'clock and does not include 10 o'clock. It is just an expression of 8:30, 9:00 and 9:30.

"0 0/30 8-9 5,20 * ?" Note that for a single trigger, some schedule requirements may be too complex to be expressed in expressions, for example: every 5 between 9:00 and 10:00 Triggered every minute, and every 20 minutes from 1:00 to 10:00 PM. The solution is to create two triggers, both of which run the same task.

Guess you like

Origin blog.csdn.net/qq_36445227/article/details/91040581