Step 1: @EnableScheduling 使能 Application 主类
@SpringBootApplication
@EnableScheduling
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
Step 2: @Scheduled 定义定时任务
@Scheduled(fixedDelay = 200)
public void task() {
// do something
}
Step 3: 了解 @Scheduled 参数使用方法
比如如何定义频率、周期间隔、延迟执行等,可以参考:https://blog.youkuaiyun.com/qq_39101581/article/details/79308851