Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of cron expression

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the example analysis of cron expression, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

An Cron expression is a string separated by 5 or 6 spaces, divided into 6 or 7 fields, each of which represents a meaning. Cron has the following two syntax formats:

(1) Seconds Minutes Hours DayofMonth Month DayofWeek Year format 1

(2) Seconds Minutes Hours DayofMonth Month DayofWeek format II

I. structure

Corn from left to right (separated by spaces): the date in the second minute hour month month the date in the week year

Second, the meaning of each field

Field permissible integers for special character seconds (Seconds) 0x 59,-* / four character minutes (Minutes) 0x 59,-* / four character hours (Hours) 0mm 23,-* / four character dates (DayofMonth) 1x 31 (but you need to consider the number of days of your month),-*? / L W C eight character months (Month) 1x 12 or JAN-DEC -* / four character week (DayofWeek) 1 / 7 integer or SUN-SAT (1=SUN),-*? / L C # eight character years (optional Left blank) (Year) 1970-2099,-* / four characters

Note: numbers are used in each field, but the following special characters can also appear, which mean:

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

(2)?: can only be used in DayofMonth and DayofWeek domains. It also matches any value of the domain, but it doesn't. Because DayofMonth and DayofWeek influence each other. For example, if you want to trigger the schedule on the 20th of each month, no matter what day it is on the 20th, you can only use the following words: 13 13 15 20 *, of which the last one can only be used? Instead of using *, if you use * to indicate that it will trigger regardless of the day of the week, it is not actually the case.

(3) -: indicates the range. For example, use 5-20 in the Minutes domain, which means that it is triggered every minute from 5 to 20 minutes.

(4) /: indicates that the start time starts to trigger, and then triggers every fixed time. For example, using 5 + 20 in Minutes field means triggering once in 5 minutes, while 25 + 45 and so on.

(5),: indicates that enumerated values are listed. For example, using 5 minutes 20 in the Minutes domain means triggering every minute at 5 and 20 minutes.

(6) L: indicates that finally, it can only appear in the DayofWeek and DayofMonth fields. If 5L is used in the DayofWeek domain, it means that it will be triggered on the last Thursday.

(7) W: indicates a valid working day (Monday to Friday), which can only appear in the DayofMonth domain, and the system will trigger the event on the nearest valid working day from the specified date. For example, if 5W is used in DayofMonth, if the 5th is Saturday, it will be triggered on the nearest working day: Friday, that is, the 4th. If the 5th is Sunday, it is triggered on the 6th (Monday); if the 5th is one of the days from Monday to Friday, it is triggered on the 5th. On the other hand, W's recent search will not cross the month.

(8) LW: these two characters can be used together to indicate the last working day of a month, that is, the last Friday.

(9) #: used to determine the day of the month, can only appear in the DayofMonth domain. For example, on April 2, it means the second Wednesday of a month.

3. Examples of commonly used expressions

(1) 0 021 *? * indicates that the task is adjusted at 2 am on the 1st of each month.

(2) 0 15 10? * MON-FRI says that homework is performed at 10:15 every day from Monday to Friday.

(3) 0 15 10? 6L 2002-2006 means that the last Friday of every month from 2002 to 2006 will be executed at 10:15

(4) 0 010, 14, 14, 16? 10:00, 2pm, 4pm every day

(5) 00 stroke 30 9-17 *? Every half hour during working hours from nine to five

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

(7) 0 012 *? Triggered at 12:00 every day

(8) 0 15 10? * triggered at 10:15 every morning

(9) 0 15 10 *? Triggered at 10:15 every morning

(10) 0 15 10 *? * triggered at 10:15 every morning

(11) 0 15 10 * *? trigger at 10:15 every morning in 2005

(12) 0 * 14 * *? Triggered every minute between 2pm and 2:59 every day

(13) 0 0 stroke 5 14 * *? Triggered every 5 minutes between 2pm and 2:55 every day

(14) 0 00 stroke 5 14 1 18 * *? Triggered every 5 minutes between 2pm and 2:55 and between 6pm and 6:55 every day

(15) 00-5 14 *? Triggered every minute between 2pm and 2:05 every day

(16) 0 10 WED 44 14? 3 trigger at 2:10 and 2:44 on Wednesday in March every year

(17) 0 15 10? * MON-FRI triggers at 10:15 from Monday to Friday

(18) 0 15 10 15 *? Triggered at 10:15 on the 15th of each month

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

(20) 0 15 10? * 6L triggered at 10:15 on the last Friday of each month

(21) 0 15 10? * 6L 2002-2005 trigger at 10:15 on the last Friday of each month from 2002 to 2005

(22) 0 15 10? * 6: 3 trigger at 10:15 on the third Friday of each month

Note:

(1) there are some subexpressions that can contain ranges or lists.

For example: the subexpression (day (week)) can be "MON-FRI", "MON,WED,FRI", "MON-WED,SAT"

The "*" character represents all possible values

Therefore, "*" represents the meaning of each month in the subexpression (month), and "*" represents each day of the week in the subexpression (day (week)).

The "/" character is used to specify the increment of the numeric value

For example, in the sub-expression (minutes), "0Universe 15" means starting at the 0th minute, every 15 minutes.

"3x20" in the subexpression (minutes) means every 20 minutes starting from the 3rd minute (it has the same meaning as "3gamet 235,43").

"?" Characters are only used in day (month) and day (week) subexpressions, indicating that no value is specified

When one of the two subexpressions is assigned a value, to avoid conflicts, you need to set the value of the other subexpression to "?"

The "L" character is only used in the day (month) and day (week) subexpressions. It is the abbreviation of the word "last".

But it has different meanings in the two subexpressions.

In the day (month) subexpression, "L" represents the last day of the month

In the day (week) self expression, "L" indicates the last day of the week, that is, SAT.

If there is a specific content before "L", it has other meanings.

For example, "6L" means the penultimate day of the month, and "FRIL" means the last Friday of the month.

Note: do not specify a list or range when using the "L" parameter, as this can cause problems

Thank you for reading this article carefully. I hope the article "sample Analysis of cron expressions" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report