1. 程式人生 > >spring boot 定時器

spring boot 定時器

啟動類新增 

@EnableScheduling

 

@Component
public class SchedulerTask {

    private int count=0;

    /**
     * @Scheduled(fixedRate = 6000) :上一次開始執行時間點之後6秒再執行
     @Scheduled(fixedDelay = 6000) :上一次執行完畢時間點之後6秒再執行
     @Scheduled(initialDelay=1000, fixedRate=6000) :第一次延遲1秒後執行,之後按fixedRate的規則每6秒執行一次
     @Scheduled(cron = "0 0 3 ? * *")  每天三點執行
     */
//    @Scheduled(fixedRate = 1000*60*60*24)
    @Scheduled(fixedRate = 1000*60*60*24)
    public void process(){
        System.out.println("this is scheduler task runing  "+(count++));
    }

}