Notes on scheduling scheduled tasks

Use the @EnableScheduling annotation on the configuration class (using the @Configuration annotation) to enable scheduled tasks, and use the @Scheduled annotation on the method to set the execution rules of the current method.

Scheduled can set the following parameters

  • cron

    This is an expression through which scheduled tasks can be configured. For rules, please see "Cron Expression Analysis"

  • zone

    Time zone

  • fixedDelay ,fixedDelayString

    Fixed delay execution

  • initialDelay,fixedRateString

    initial delay time

  • fixedRate,initialDelayString

    Fixed frequency execution

The difference between the following three parameters with and without String is that one is of long type and the other is of String type, both of which can be copied directly, with milliseconds as the basic unit. Moreover, the long type can fill in simple calculation formulas (addition, subtraction, multiplication, and division), and the String type can directly use ${} to get the value from the configuration file.

Guess you like

Origin blog.csdn.net/jl15988/article/details/116204699