Setting-----Corn expression for time expressions in quartz
(Note: This is to let me see a more clear blog, but sorry, did not find the original author, if there is infringement, please inform)
Time format: <!--s M h d M W (?) y (?)-->, respectively: sec > Min > Hour > Day > Month > Week > year,
Example:
1. When to execute every day:
<value>0 * * </value>: The following is done daily 23:59:00
<value>0 11,12 * *? </value>: Daily 11:01,11:02,11:03; 12:01,12:02,12:03 Sub-task execution
2. How often do you perform:
Summary description:
The time field of a cron expression, in addition to allowing the setting of numeric values, can also use some special characters, providing lists, scopes, wildcards and other functions, as described below:
Asterisk (*): Available in all fields, representing every moment of the corresponding time field, for example, * in the minute field, means "per minute";
Question mark (?): This character is used only in date and weekday fields, and it is usually specified as "meaningless value", which is equivalent to a dot character;
Minus sign (-): expresses a range, such as the use of "10-12" in the hour field, that is, from 10 to 12 points, that is, 10,11,12;
Comma (,): Expresses a list value, such as "Mon,wed,fri" in the day of the week field, that is, Monday, Wednesday, and Friday;
Slash (/): The X/y expression is a sequence of equal steps, the value is the start, and Y is the increment step value. If you use 0/15 in the minute field, it is expressed as 0,15,30 and 45 seconds, and 5/15 in the minute field represents 5,20,35,50, you can also use */y, which is equivalent to 0/y;
==================================================
The format of the Quartz cron expression is very similar to that of the UNIX cron format, but there is still a little obvious difference. One of the differences is that the Quartz format supports scheduling down to the second level, while the UNIX cron program only supports up to minute levels. Many of our trigger plans are based on a second-level increment (for example, every 45 seconds), so this is a very good difference.
In UNIX Cron, the job (or command) to be executed is stored in a cron expression, at the sixth domain location. Quartz uses cron expressions to store execution plans. A crontrigger that references a cron expression is associated with the job at the scheduled time.
Another difference from the UNIX cron expression is the number of domains that are supported in an expression. UNIX gives five domains (minutes, hours, days, months, and weeks), and Quartz provides seven domains. Table 5.1 lists the seven domains supported by the Quartz cron expression.
Table 5.1. Quartz Cron expressions support to seven domains
Name |
Whether you must |
Allowed values |
Special characters |
Seconds |
Is |
0-59 |
, - * / |
Score of |
Is |
0-59 |
, - * / |
When |
Is |
0-23 |
, - * / |
Day |
Is |
1-31 |
, - * ? /L W C |
Month |
Is |
1-12 or Jan-dec |
, - * / |
Week |
Is |
1-7 or Sun-sat |
, - * ? /L C # |
Years |
Whether |
Empty or 1970-2099 |
, - * / |
The names of the month and week are case insensitive.FRI andFri is the same.
There are spaces between fields, which is the same as UNIX cron. It is indisputable that the simplest expression that we can write looks like this:
* * * ? * *
This expression fires a deployed job every second (every minute, every hour, every day).
• Understanding special characters
Like UNIX cron, Quartz cron expressions support the creation of more complex execution plans with special characters. However, Quartz is richer in support of special characters than standard UNIX cron expressions.
* Asterisk
Use an asterisk (*) to indicate that you want to include all valid values on this domain. For example, using an asterisk on a month field means that the trigger is triggered every month.
Examples of expression patterns:
0 * 17 * *?
Meaning: Trigger is fired every minute from 5 o'clock in the afternoon to 5:59 each day. It stops at 5:59 because the value 17 is on the hour field, and at 6 o'clock in the afternoon, the hour becomes 18, and the trigger is no longer heeded until the next day of 5 o'clock in the afternoon.
Used when you want trigger to be fired on all valid values for the domainCharacters
? Question mark
? Numbers can only be used inDay andDomain, but cannot be used concurrently on both domains. You can think? The character is "I don't care what the value is on that field." "This differs from the asterisk, which indicates each value on the field." Is that you do not specify a value for the field.
The reason why a value cannot be specified at the same time on both domains is difficult to interpret or even incomprehensible. Basically, assuming that you specify a value at the same time, the meaning becomes ambiguous: consider if an expression isThere is a value of 11 on the field, at the same timeSpecified on the week field.WED. So is it to trigger only in the 11th of each month, and exactly the day of Wednesday is excited? Or was it fired at number 11th in every Wednesday? The way to remove this ambiguity is that you cannot specify values on both domains at the same time.
Just remember that if you specify a value for one of these two fields, you must put a?。
Examples of expression patterns:
0 10,44 14? 3 WEB
Meaning: Every Wednesday 2:10 and 2:44 in March is triggered.
, comma
Comma) is used to specify a list of values on a domain. For example, using the value 0,15,30,45 on the second field means that a trigger is triggered every 15 seconds.
Examples of expression patterns:
0 0,15,30,45 * * *?
Meaning: The trigger is triggered once per quarter.
/Slash
Slash (/) is used for the increment of the timesheet. We've just used a comma to indicate the increment every 15 minutes, but we can also write this0/15.
Examples of expression patterns:
0/15 0/30 * * *?
Meaning: Trigger trigger every 15 seconds at the hour and the slightest.
-Medium Dash
Medium Dash (-) to specify a range. For example, 3-8 on the hour field means "3,4,5,6,7 and 8 points." "The value of the domain does not allow a rollback, so a value like 50-10 is not allowed.
Examples of expression patterns:
0 45 3-8? * *
Meaning: 3 points in the morning to 8 points in the morning of 45 ticks trigger trigger.
L Letter
L describes the last value allowed on a domain. It is only Day and week domain support. When used on a day field, represents the last day of the month specified on the month field. For example, a jan sep, then L will herald the trigger on September 30. In other words, the trigger is triggered on the last day of the corresponding month, regardless of the month specified. The
expression 0 0 8 L * meaning to trigger trigger at 8:00 on the last day of each month. In
When l letter is used on the field of the week, indicating the last day of the week, which is Saturday (or the number 7). So if you need to trigger trigger in the last Saturday afternoon of the month in 11:59, you can use such expressions 0.
When used with l to represent the last one weeks of the month X. For example, the expression 0 0? * 2L is said to trigger trigger at the last one weeks of each month.
Do not allow range and list values to be associated with L
Although you can use the days of the week (1-7) with L, you are not allowed to use a range value and a list value with L. This can produce unpredictable results. |
W Letter
The W character represents weekdays (MON-FRI), and can only be used in the day domain. It is used to specify the most recent weekday from the specified day. Most of the business process is based on the work week, so the W character may be very important. For example, in the Japanese domain,15w means "the most recent weekday from 15th in the month." "If number 15th is Saturday, then trigger will be triggered at 14th (Friday), because Thursday is closer to 15th than in Monday (this is number 17th). 15w, may be at 14th (15th is Saturday) or 15th ( Number 15th is Sunday) trigger, that is, can only appear in the adjacent day, if the day of the 15th is on weekdays directly on the day of execution. w can only be used in the specified The day is a single day and cannot be a range or list value.
#
# character can only be used for the Span style= "color: #80080;" In the week field. It is used to specify which day of the week of the month. For example, if you specify a value of 6#3, which means the third Friday of the month (6= Friday, #3意味着月份中的第三周). Another example 2#1 means the first Monday of the month (2= Monday, #1意味着月份中的第一周). Note that if you specify #5, but there is no 5th week in the month, then the month does not trigger.
The Cron expression Cookbook here is designed to provide scenarios for common execution requirements. Although it is not possible to enumerate all the expressions, the following should provide sufficient examples to meet your business needs.
• Cron Expressions for minutes
Table 5.1. Task Scheduler Cron expressions that include minute frequencies
Usage |
An expression |
Daily trigger per minute from 5:00pm to 5:59 pm |
0 * 17 * *? |
Triggers every five minutes from 11:00am to 11:55 pm per day |
0 0/5 23 * *?
|
Every five minutes from 3:00 to 3:55 pm and 6:00pm to 6:55 pm per day |
0 0/5 15,18 * *?
|
Daily trigger per minute from 5:00pm to 5:05 am |
0 0-5 5 * *? |
• Cron expressions on the day
Table 5.2. Cron expression on a task plan based on daily frequency
Usage |
An expression |
Every day, I AM |
0 0 3 * *? |
Everyday of the day (another way) |
0 0 3? * * |
Daily 12:00pm (Noon) |
0 0 12 * *? |
10:15 AM per day in 2005 |
0 15 10 * *? 2005 |
• Cron expressions for week and month
table 5.3. Cron expressions on task schedules based on weekly and/or monthly frequency
Usage |
An expression |
In every Monday, two, three and Thursday of 10:15 AM |
0 15 10? * Mon-fri |
10:15 AM, number 15th per month. |
0 15 10 15 *? |
10:15 AM on the last day of the month |
0 L *? |
10:15 AM in the last Friday of the month |
0 15 10? * 6L |
In the 2002, 2003, 2004, and 2005 months of the month of the last Friday 10:15 AM |
0 15 10? * 6L 2002-2005 |
10:15 AM, third Friday per month |
0 15 10? * 6#3 |
Every five days (noon) per month from the first day |
0 0 12 1/5 *? |
Every November 11 11:11 AM |
0 11 11 11 11? |
March 2:10 pm and 2:44 pm for each Wednesday |
0 10,44 14? 3 WED |
Eight. Create an instant-triggered Trigger
Sometimes, you need to execute a job immediately. For example, imagine that you are building a GUI program and allowing users to execute it immediately. In another example, you may have detected that a JOB has not been executed successfully, so you want to run it again at once. In Quartz 1.5, several methods were added to the Triggerutils class, making it easy to implement those things. Code 5.4 shows how to deploy a job and just let it execute immediately.
Java Timing framework: expression settings