@Scheduled the parameters Detailed notes

@Scheduled the parameters Detailed notes

Use @Scheduled annotation can refer to this: https: //www.cnblogs.com/mengw/p/11564338.html

Parameter Description

1. cron

Receiving a parameter cron表达式, cron表达式a string of 5 or 6 separated by a space, a total of six or seven separate domains, each domain representing a meaning.

cron expression syntax
[秒] [分] [小时] [日] [月] [周] [年]

Note: [years] is not required domain, you can omit [years], then a total of six domains

No. Explanation Mandatory Which allowed the value of Allow wildcard
1 second Yes 0-59 , - * /
2 Minute Yes 0-59 , - * /
3 Time Yes 0-23 , - * /
4 day Yes 1-31 , - * ? / L W
5 month Yes 1-12 / JAN-DEC , - * /
6 week Yes 1-7 or SUN-SAT , - * ? / L #
7 year no 1970-2099 , - * /

Cron Expression Builder Online

Wildcard Description:
  • *It represents all the values. For example: In the sub-field setting * indicates every minute trigger.
  • ?He said they did not specify the value. Scene used to not care about the value of the current setting of this field. For example: To trigger on the 10th of each month of operation, but is not concerned about a few weeks, so it is necessary that the field is set for the specific peripheral position is set to 00010 * "?"?
  • -Representing the interval. For example, set up "10-12" on the hour, 10, 11, represents the point will be triggered.
  • , It represents specify multiple values, such as setting "MON, WED, FRI" in the week field said on Monday, Wednesday and Friday trigger
  • /For incrementing trigger. As set "5/15" above represents the second for 5 seconds, every 15 seconds by a trigger (5,20,35,50). Set in the month field '1/3' Start No. 1 a month, once every three days triggered shown.
  • LIt indicates that the last meaning. On the field, set the day, represents the last day (based on the current month, if February is also based on whether it is a leap year [leap]) the month, expressed Saturday, the equivalent of "7" or "SAT" in the week field. If the "L" digitally before, indicates the last of the data. For example, setting this format "6L" in the week field, it means "the last Friday of the month."
  • WIt represents, for example set to "15W" on the daily field closest to the date specified weekday (Monday to Friday), represents the 15th of each month from recent days that trigger. If the 15th happens to be Saturday, you find the nearest Friday (14) is triggered, if the number 15 is the weekend, then look for the nearest next Monday (16) is triggered. If the number in just 15 working days (Monday to Sunday e), then triggered in the day. If you specify the format of "1W", it said 1 month later recent days triggered. If Saturday is the No. 1, No. 3 will be triggered Monday. (Note, "W" can only be set before the specific numbers are not allowed interval "-").
  • #Number (of every month the first few days of the week), for example on the field Week "6 # 3" represents the third Saturday of every month. Note that if you specify "# 5", not just on Saturday fifth week It does not trigger this configuration (with the mother's Day and father's Day very appropriate); Tip: 'L' and 'W' may be a combination. If set to "LW" in the Japanese field, then triggered the last business day of the month; week to set the field, the use of English letters are not case sensitive, and that is the same as MON mon.
Examples

Executed once every 5 seconds: / 5 * * *?

Executed once every minute: 0 /1 * *?

23:00 executed once a day: 0023 * *?

1:00 executed once a day: 001 * *?

Monthly No. 1 1:00 execution time: 0011 *?

The last day of each month 23:00 executed once: 0 0 23 L *?

Weekly Sunday 1:00 to implement once: 0 0 1 * L?

In 26 points, 29 points, 33 points is performed once: 0 26,29,33 * * *?

Daily 0:00, 13:00, 18:00, 21:00 executed once: 00 0,13,18,21 * *?

cron expression placeholder

Further, cronthe attribute received cron表达式with placeholders. eg:

Profiles:

time:
  cron: */5 * * * * *
  interval: 5

Performed once every 5 seconds:

    @Scheduled(cron="${time.cron}")
    void testPlaceholder1() {
        System.out.println("Execute at " + System.currentTimeMillis());
    }

    @Scheduled(cron="*/${time.interval} * * * * *")
    void testPlaceholder2() {
        System.out.println("Execute at " + System.currentTimeMillis());
    }

2. zone

Time zone, receiving one java.util.TimeZone#ID. cron表达式It will be resolved based on the time zone. The default is an empty string, that is to take the server location's time zone. For example, we generally use the time zone Asia/Shanghai. The field we generally empty.

3. fixedDelay

After the last point of execution completion time how long the re-executed. Such as:

@Scheduled(fixedDelay = 5000) //上一次执行完毕时间点之后5秒再执行

4. fixedDelayString

The 3. fixedDelaysame meaning, except as a string. The only difference is that support placeholders. Such as:

@Scheduled(fixedDelayString = "5000") //上一次执行完毕时间点之后5秒再执行

Placeholder used (the configuration file configuration: time.fixedDelay = 5000):

    @Scheduled(fixedDelayString = "${time.fixedDelay}")
    void testFixedDelayString() {
        System.out.println("Execute at " + System.currentTimeMillis());
    }

5. fixedRate

After the last point in time how long it started to perform again. Such as:

@Scheduled(fixedRate = 5000) //上一次开始执行时间点之后5秒再执行

6. fixedRateString

The 5. fixedRatesame meaning, except as a string. The only difference is that support placeholders.

7. initialDelay

How long before the first delay execution. Such as:

@Scheduled(initialDelay=1000, fixedRate=5000) //第一次延迟1秒后执行,之后按fixedRate的规则每5秒执行一次

8. initialDelayString

The 7. initialDelaysame meaning, except as a string. The only difference is that support placeholders.

Guess you like

Origin www.cnblogs.com/mengw/p/11564357.html