版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1.定时器配置
@SpringBootApplication @EnableScheduling //定时器 public class SpringBootTasksApplication { public static void main(String[] args) { SpringApplication.run(SpringBootTasksApplication.class, args); } }
@Component @Slf4j public class ScheduledTasks { private static final SimpleDateFormat dfm = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 5000) public void reportCurrentTime(){ log.info("The time is now{}",dfm.format(new Date())); } @Scheduled(cron = "0 35 10 * * ? ") public void reportCurrentTime1(){ log.info("The time is now234{}",dfm.format(new Date())); } }
3.corn 表达式
规则:秒 分 时 日 月 星期 年
0 0 10 1 1 ? //1月1日 10:00:00 点
corn 在线表达式 url : http://cron.qqe2.com/