本文介紹在Spring Boot 中如何使用定時任務,使用非常簡單,就不做過多說明了。
下面是代碼類:
package org.springboot.sample.config;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.context.annotation.Configuration;import org.springframework.scheduling.annotation.EnableScheduling;import org.springframework.scheduling.annotation.Scheduled;/** * 定時任務配置類 * * @author 單紅宇(365384722) * @myblog http://blog.csdn.net/catoop/ * @create 2016年3月21日 */@Configuration@EnableScheduling // 啟用定時任務public class SchedulingConfig { private final Logger logger = LoggerFactory.getLogger(getClass()); @Scheduled(cron = "0/20 * * * * ?") // 每20秒執行一次 public void scheduler() { logger.info(">>>>>>>>>>>>> scheduled ... "); }}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答
圖片精選