Ali interviewer: corn expression

Our database usually writes a lot of SQL statements. Today we are going to learn CRON expressions, which are timed tasks. There are some generation methods on the Internet, but I want to write by myself here and don’t want to rely on online generators often.

Cron is composed of seconds, minutes, hours, days, months, weeks, and years

Special characters allowed in the value of the field name

Seconds 0-59,-* /

Points 0-59,-* /

Hours 0-23,-* /

Day 1-31,-*? / LWC

月 1-12 or JAN-DEC , - * /

Day of the week 1-7 or SUN-SAT,-*? / LC #

Year (optional field) empty, 1970-2099,-* /

In order

Seconds (0~59)

Minute (0~59)

Hour (0~23)

Day (month) (1~31, but you need to consider the number of days in the month)

Month (1~12 or JAN-DEC)

Day (week) (1~7 1=SUN or SUN, MON, TUE, WED, THU, FRI, SAT)

Year (1970-2099)

Each element can be a value (such as 6), a continuous interval (9-12), an interval time (8-18/4) (/ means every 4 hours), a list (1, 3, 5) ,Wildcard. Since the two elements "day of the month" and "day of the week" are mutually exclusive, it is necessary to set one of them?

"?" character: indicates an uncertain value

"," character: specify several values

"-" Character: Specify a range of values. Example: 0-9

"/" Character: Specify the increment of a value. n/m means starting from n and increasing by m each time, which can be understood as a step value

For example: 4/5 starts from 4 and triggers once to 9, 14, 19, 23. It can be understood that it starts from 4, increases by 5 and becomes 9, and increases from 9 by 5. This will not increase indefinitely. If placed The second field, the maximum is 59, and the date field is 31

"L" character: used in day to represent the last day of a month, used in week to represent the last week of the month X, 5L represents the last week of the month 4, 1 represents Sunday, and so on

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

"W": Indicates valid working days (Monday to Friday), which can only appear in the DayofMonth field, and the system will trigger the event on the nearest valid working day from the specified date. For example: Use 5W 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 will be triggered on the 6th (Monday); if the 5th is a day from Monday to Friday, it will be triggered on the 5th. Another point, W’s recent search will not span the month

"LW": These two characters can be used together to indicate the last working day of a month, that is, the last Friday

"#" character: indicates the week X of the month. 6#3 means the 3rd Friday of a certain month, the Sunday is 1, and so on,

"?": Only used for two sub-expressions of day (month) and day (week), meaning no value is specified

"*": Used to specify all values. For example: "*" means "every minute" in the minute field.

When one of the two sub-expressions is assigned a value, in order to avoid conflicts, the value of the other sub-expression needs to be set to "?"

"C": Allowed to appear in the date field and week field. This character depends on a designated "calendar". That is to say, the value of this expression depends on the calculation result of the related "calendar". If there is no "calendar" associated, it is equivalent to all included "calendars". For example, if the date field is "5C", it means the first day in the associated "calendar", or 5 days after the first day of the beginning of the month. The week field is "1C", which means the first day in the associated "calendar", or the day after the first day of the week, that is, the day after Sunday (Monday)

Note: C is rarely used in normal times, just remember


Above are some videos and interview questions I collected.

For software testing friends, it should be the most comprehensive and complete interview preparation warehouse. In order to better organize each module, I also refer to many high-quality blog posts and projects on the Internet, and strive not to miss every knowledge point. Friends relied on these contents to review, and got offers from big factories such as BATJ. This warehouse has also helped many software test learners, and I hope it can also help you.

Follow my WeChat public account [Programmer Erhei] to get the
link and this statement for free.
Original link: https://blog.csdn.net/m0_52668874/article/details/114988108

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/115014863