Quartz cron trigger cron expression format

Source: Internet
Author: User

From: http://hi.baidu.com/wjx_5893/blog/item/1c28057fb2d93f062a388a67.html

 

The quartz cron expression supports whether to allow special characters for seven domain names
Seconds are 0-59 ,-*/
0-59 ,-*/
0-23 ,-*/
The day is 1-31 ,-*? /L W C
Month is 1-12 or JAN-DEC ,-*/
The Week is 1-7 or sun-Sat ,-*? /L c #
Yearly blank or 1970-2099 ,-*/

The names of months and weeks are case-insensitive. Fri and Fri are the same.

Fields are separated by spaces.

***? ** // This expression inspires a deployed job every second (every minute, every hour, or every day.

Understanding special characters 

* Asterisks

The asterisk (*) indicates that you want to include all valid values in this field. For example, using an asterisk in a month domain means that the trigger is triggered every month.

Expression examples:

0*17 **?

Trigger is triggered every minute from five o'clock P.M. to PM. It stops at six o'clock P.M. pm because the value 17 is in the small time domain. At five o'clock P.M., the hour changes to 18, and the trigger is ignored until of the next day.

Use the * character when you want the trigger to be fired on all valid values of this field.


? Question mark

? It can only be used in the day and week domains, but cannot be used in both domains. You can think? The character is "I don't care about the value in this field. "Unlike asterisks, asterisks indicate each value in this field .? It means that no value is specified for this field.

The reason why these two fields cannot be specified at the same time is hard to explain or even hard to understand. Basically, if a value is specified at the same time, the meaning will become ambiguous: consider, if an expression has a value of 11 on the daily domain, and wed is specified on the weekly domain. So is Trigger only on the 11th day of every month, and is triggered on Wednesday? Or is it triggered on the 11th of every Wednesday? To remove such ambiguity, you cannot specify values for both domains.

Remember, if you specify a value for one of these two fields, you must put one? on the other ?.

Expression examples:

0 10, 44 14? 3 Web

Triggered at PM and PM on every Wednesday of March 13, March


, Comma 

Comma (,) is used to specify a value list for a domain. For example, if the value 0, 15, 30, and 45 are used, a trigger is triggered every 15 seconds.

Expression examples:

0 0, 15, 30, 45 ***?

Meaning: trigger a trigger within a clock.

/Slash 

A slash (/) is used to increase the number of timelines. We just used a comma to indicate the increase every 15 minutes, but we can also write it as 0/15.

Expression examples:

0/15 0/30 ***?

Meaning: trigger every 15 seconds at the hour and half.

-Dashes 

Hyphens (-) are used to specify a range. For example, 3-8 in a small time domain means "3, 4, 5, 6, 7, and 8. "Domain values cannot be rolled back, so values like 50-10 are not allowed.

Expression examples:

0 45 3-8? **

Meaning: trigger at AM to AM.

L letters 

L indicates the last value allowed on a domain. It is only supported by day and week domains. When used in the day domain, it indicates the last day of the month specified in the month domain. For example, if Jan is specified in the current month, the L in the Japanese domain will trigger the trigger on January 1, January 31. If the monthly domain is SEP, L indicates that the domain will be triggered on March 13, September 30. In other words, no matter which month is specified, trigger is triggered on the last day of the corresponding month.

Expression 0 0 8 L *? Trigger is triggered at AM on the last day of each month. In the monthly domain, * indicates "every month ".

When l is used in the week domain, it indicates the last day of the week, that is, Saturday (or number 7 ). So if you need to trigger a trigger at on the last Saturday of each month, you can use this expression 0 59 23? * L.

When used in the week domain, you can use a number to connect to L to represent the last week X of the month. For example, the expression 0 0 12? * 2L calls trigger on the last Monday of each month.

Do not use range and List Value with L

Although you can use the number of weeks (1-7) with L, you are not allowed to use a range value and List Value with L. This produces unpredictable results.

W letters

The W character represents the day (Mon-Fri) and can only be used in the day domain. It is used to specify a calendar day closest to a specified day. Most of the business processing is based on the work week, So w characters may be very important. For example, 15 W in the Japanese domain means "the last day of the month on the 15th. "If the 15th is Saturday, the trigger will be triggered on the 14th (Thursday), because the last Monday is the 15th, and the example will also be the 17th (unmi note: it will not be triggered on the 17th. If it is 15 W, it may be triggered on the 14th (Saturday on the 15th) or 15th (Sunday on the 15th, that is, it can only appear in the adjacent day. If the day 15 is normal, it will be executed on the same day ). W can only be used for a single day in the specified daily domain, and cannot be a range or list value.

# Well ID 

# Characters can only be used in the weekly domain. It is used to specify the day of the week in the month. For example, if you specify the value of the weekly domain as 6 #3, it means the third Friday of a month (6 = Friday, #3 means the third week of the month ). Another example 2 #1 indicates the first Monday of a month (2 = Monday, #1 indicates the first week of the month ). Note: If you specify #5, but there are no 5th weeks in the month, this month will not be triggered.


Cron expression cookbook

The cron expression cookbook here is designed to provide a solution for common execution requirements. Although it is impossible to list all expressions, the following examples should be provided to meet your business needs.

· Minute cron expression

Table 5.1. cron expression usage expressions that contain minute-level task plans
0*17 ** triggered every minute from PM to pm every day **?

0 0/5 23 triggered every five minutes from PM to pm every day **?

Triggered every five minutes from to PM and PM to pm every day 0 0/5 **?

Every minute from AM to am triggers 0 0-5 5 5 **?


· Cron expression of explain 

Table 5.2. cron expression usage expression of the task plan based on the daily frequency
AM 0 0 3 ** every day **?
Am every day (another way) 0 0 3? **
PM (noon) every day 0 0 12 **?
In 2005, every day at AM 0 15 10 **? 2005

· Cron expressions for weeks and months 

Table 5.3. cron expression usage expression of the task plan based on the week/month frequency
Every Monday, two, three, and Thursday at AM 0 15 10? * MON-FRI
AM 0 15 10 15 * on the 15th of every month *?
AM 0 15 10 L * on the last day of each month *?
10: 15 am 0 15 10 on the last Friday of every month? * 6l
In 2002,200 3, 2004, and the last Friday of the month in 2005 at AM 0 15 10? * 6l 2002-2005
AM 0 15 10 on the third Friday of every month? * 6 #3
PM (noon) every five days from the first day of each month 0 12 1/5 *?
Every November 11 AM 0 11 11 11 11?

And pm every Wednesday in February March, 44 14? 3 wed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.