java - quartz的cron表达式的问题
黄舟
黄舟 2017-04-18 10:26:49
0
3
411

在cron表达式中0 和* 的区别,看了文档之后不是很清楚,自己执行了下 感觉差不多。
比如 */26 和 0/26有什么区别呢?什么场景下 用哪个呢?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
Ty80

Let me tell you about my own experience.
The problem I encountered at that time was the 46th place. The fourth digit represents the day and the sixth digit represents the week.
If there are numbers on the day, such as 1, 2, 3, then write * for the week, which means that no matter what day of the week, as long as the day is 1, 2, 3, the conditions are met.
And vice versa.

In my opinion, the meaning of the

* number is that no matter what number it is, it meets the conditions.
The following is forwarded from someone else’s blog, any infringement will be deleted.

Cron expression includes the following 7 fields:

Format: [Second] [Minute] [Hour] [Day] [Month] [Week] [Year]
Serial number description: required or not. Allowed values. Allowed wildcards.
1 second is 0-59, - * /
2 Minutes are 0-59, - * /
3 hours are 0-23, - * /
4 days are 1-31, - * ? / L W
May is 1-12 or JAN-DEC, - * /
6 Week is 1-7 or SUN-SAT , - * ? / L #
7 years is empty or 1970-2099 , - * /

Wildcard description:

  1. The backslash (/) character represents an incremental value. For example, "5/15" in the seconds field means every 15 seconds starting at second 5.

  2. The
  3. asterisk () character is a wildcard character, which means that the field can accept any possible value (for example: setting "" on the minutes field means that it will trigger every minute).

  4. Question mark (?) The question mark indicates that this field does not contain a specific value. So, if you specify a date within the month, you can insert a "?" in the date-of-month field to indicate that the day-of-week value does not matter. The letter L character is short for last. Put it in the date of month field to schedule execution on the last day of the month. In a day-of-the-week field, "L" equals "7" if present by itself, otherwise it represents the last instance of a day-of-the-week within the month. So "0L" means it is scheduled to be executed on the last Sunday of the month.

    • represents the interval, for example, setting "10-12" on the hour means that it will be triggered at 10, 11, and 12 o'clock.

  5. Comma (, ) means specifying multiple values, for example, setting "MON,WED,FRI" on the week field means triggering on Monday, Wednesday and Friday

  6. The pound (#) character specifies specific working day instances for a given month. Put "MON#2" in the day-of-week field to schedule the task on the second Monday of the month.

  7. L means the last word. In the day field setting, it represents the last day of the month (according to the current month, if it is February, it will also depend on whether it is a leap year), and in the week field it represents Saturday, which is equivalent to "7" or "SAT". If you add a number before "L", it means the last one of the data. For example, setting a format like "6L" on the week field means "the last Friday of this month".

  8. W represents the working day closest to the specified date (Monday to Friday). For example, setting "15W" on the day field means that the working day closest to the 15th of each month is triggered. If the 15th happens to be a Saturday, the trigger will be found on the nearest Friday (the 14th). If the 15th is a weekend, the trigger will be found on the nearest Monday (the 16th). If the 15th happens to be on a working day (Monday to Sunday) 5), it will be triggered on that day. If the specified format is "1W", it means that it is triggered on the nearest working day after the 1st of each month. If the 1st falls on a Saturday, it will be triggered on Monday the 3rd. (Note, only specific numbers can be set before "W", and the interval "-" is not allowed).
    Note: 'L' and 'W' can be used in combination. If "LW" is set on the day field, it means triggering on the last working day of the month.

Commonly used examples:
0 10 * ?--------------Execute once every 10 minutes every hour
0 0/32 8,12 ? ------ ----Execute once every day at 8:32,12:32
0 0/2 * ?--------------Execute once every 2 minutes
0 0 12 ?- ---------------Triggered at 12:00 noon every day
0 15 10 ? ---------------Triggered at 10:15am every day
0 15 10 ?---------------Triggered every day at 10:15 am
0 15 10 ? *--------------- Triggered every day at 10:15 AM
0 15 10 ? 2005---------------Triggered every day at 10:15 AM in 2005
0 14 * ?--- ----------Triggered every minute every day between 2:00 and 2:59 pm
0 0/5 14 ?------------- --Triggered every 5 minutes every day between 2:00 and 2:59 PM
0 0/5 14,18 ?---------------Every day at 2 PM: Trigger every 5 minutes between 00 to 2:59 and 6:00 to 6:59
0 0-5 14 ?---------------Daily at 2pm: Triggers every minute between 00 and 2:05
0 10,44 14 ? 3 WED ---------------Every Wednesday in March at 2:00 pm and 2:44 pm Trigger
0 15 10 ? * MON-FRI---------------Trigger every day from Monday to Friday at 10:15 am
0 15 10 15 * ?------ ----------Triggered at 10:15 am every 15 days of each month
0 15 10 L * ?---------------Triggered at 10:15 AM every 15th day of each month Triggered at 10:15 am on the last day
0 15 10 ? * 6L---------------Triggered at 10:15 am on the last Friday of each month
0 15 10 ? * 6L 2002-2005---------------Triggered at 10:15 am on the last Friday of each month in 2002, 2003, 2004 and 2005
0 15 10 ? * 6# 3---------------Triggered at 10:15 am on the third Friday of every month
0 0 12 1/5 * ?---------- -----Triggered at 12:00 noon every 5 days starting from the first day of each month

0 11 11 11 11 ?---------------Triggered at 11:11 am every November 11th.

刘奇

0 and * are very different when used alone.
The documentation explains about : ("all values") - used to select all values ​​within a field. For example, "" in the minute field means *"every minute”.

比如:0 * * * * ? 是每分钟执行一次,而且是在0秒的时候.

        * * * * * ? 是每秒执行一次

No relevant information was found when used in combination with /, but judging from the test: 0/26 is the same as */26.

左手右手慢动作

There are ways to generate expressions online

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!