170627、springboot編程之定時任務
阿新 • • 發佈:2017-08-21
import text frame 分享 void col 項目 清單 pac
springboot定時任務,比較簡單!
1、編寫DemoSchedule.java類
package com.rick.common.schedule; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.text.SimpleDateFormat;import java.util.Calendar; /** * Desc : 定時任務 * User : RICK * Time : 2017/8/21 21:16 */ @Configuration @EnableScheduling public class DemoSchedule { //cron表達式 秒分時 日月周 年 @Scheduled(cron = "0/10 * * * * ?") //每10秒執行一次 public void demoPrint(){ System.out.println("現在時間:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime())); } }
2、啟動項目測試
3、項目清單
170627、springboot編程之定時任務