javascript
java 创建定时器_SpringBoot创建定时任务
之前總結過spring+quartz實現定時任務的整合http://www.cnblogs.com/gdpuzxs/p/6663725.html,而springboot創建定時任務則是相當簡單。
(1)在springboot主類中@EnableScheduling注解,啟用定時任務的配置,如下:
(2)創建定時任務實現類,如下:
package springboot.web;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ScheduledTasks {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(cron="0 */1 * * * ?")
public void reportCurrentTime() {
System.out.println("每一分鐘執行一次:" + dateFormat.format(new Date()));
}
}
執行結果,如下:
https://www.cnblogs.com/gdpuzxs/category/1035931.html
總結
以上是生活随笔為你收集整理的java 创建定时器_SpringBoot创建定时任务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10怎么用命令重新安装内置应用 W
- 下一篇: spring项目搭建云服务器,Sprin