标签:rate 定时执行 目的 vat ble ntb scheduled stat pre
在Spring Boot 的主类加入 @EnableScheduling
注解,启用定时任务的配置;
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
使用 @Scheduled(fixedRate = 1000)
注解实现类需要定时执行的方法。
@Component
public class ScheduledTasks implements Runnable{
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Override
@Scheduled(fixedRate = 1000)
public void run() {
System.out.println("Current: " + dateFormat.format(new Date()));
}
}
标签:rate 定时执行 目的 vat ble ntb scheduled stat pre
原文地址:https://www.cnblogs.com/lshare/p/11334423.html