springboot 之 定时器

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_38233650/article/details/90412287
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/

猜你喜欢

转载自blog.csdn.net/qq_38233650/article/details/90412287
今日推荐