1. Create a scheduled task

SpringBoot has a built-in scheduled task module

  1. Add @ to start classEnableSchedulingThe scheduled task function is enabled
  2. Annotate methods that need to start scheduled tasks@Schedule. And set the scan time
    • Cron expression configuration:@Scheduled(cron = "0/5 * * * * ?" ), the expression can be configured in the configuration file for easy modification
    • Fixed interval: Add @scheduled (initialDelay = 4000, fixedRate = 6000) to the annotations. The initial call delay is 4 seconds and the call is Scheduled every 6 seconds
    • FixedDelay: @scheduled (initialDelay = 4000, fixedDelay = 6000) the initial call delay is 4 seconds, and the next call is 6 seconds after the task ends