spring boot启动定时任务
作者:
刘书生 | 来源:发表于
2019-07-22 15:57 被阅读0次package cn.wit.zmx.quartz;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
@Component
@EnableScheduling
@Configurable
public class ScheduledTasks {
//启动时执行一次,之后每30s执行一次
@Scheduled(fixedRate = 1000 * 30)
public void reportCurrentTime(){
System.out.println ("Scheduling Tasks Examples: The time is now " + dateFormat ().format (new Date()));
}
//启动后,每1分钟执行一次
@Scheduled(cron = "0 */1 * * * * ")
public void reportCurrentByCron(){
System.out.println ("Scheduling Tasks Examples By Cron: The time is now " + dateFormat ().format (new Date ()));
}
private SimpleDateFormat dateFormat(){
return new SimpleDateFormat ("HH:mm:ss");
}
}
本文标题:spring boot启动定时任务
本文链接:https://www.haomeiwen.com/subject/bwewlctx.html
网友评论