首頁  >  文章  >  Java  >  Spring Boot實作定時任務的java程式碼實例

Spring Boot實作定時任務的java程式碼實例

Y2J
Y2J原創
2017-05-04 09:54:341713瀏覽

這篇文章主要介紹了Spring Boot定時任務的使用實例代碼,需要的朋友可以參考下

Spring Boot中配置定時任務極其簡單......下面看下實例代碼:

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.Date;
/**
 * Created by winner_0715 on 2017/4/18.
 */
@Configuration
@EnableScheduling
public class SchedulingConfig {
  // 每5秒执行一次
  @Scheduled(cron = "0/5 * * * * ?")
  public void scheduler() {
    System.out.println("SchedulingConfig.scheduler()" + 
        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
  }
}

以上是Spring Boot實作定時任務的java程式碼實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn