spring 註釋形式的定時器

@EnableScheduling主類中加入註釋

@Component
public class ScheduledTest {

//fixedRate任務兩次執行時間間隔是任務的開始點,而 fixedDelay 的間隔是前次任務的結束與下次任務的開始。
    @Scheduled(fixedRate = 5000)
    public void scheduledDemo(){
        System.out.println("scheduled - fixedRate - print time every 5 seconds:{}"+System.currentTimeMillis() );
    }

//cron表達式
    @Scheduled(cron = "0 0/1 * * * ?")
    public void runa(){
        System.out.println("當前時間"+System.currentTimeMillis());
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章