spring定时任务
TaskScheduler 任务调度者
TaskExecutor  任务执行者

@EnableScheduling //开启定时功能的注解
@Scheduled //什么时候执行

Cron表达式

1、使用方式 开启定时功能注解,在启动类上

2、将类对象添加到Spring容器中后在定时执行的方法上添加@Scheduled 注解,并写好Cron表达式说明执行时间

//在特定时间执行这个方法   Timer
    //秒 分 时 日 月 星期
    @Scheduled(cron = "0 39 * * * ?")
    public void hello(){
        System.out.println("hello 执行了");
    }

常用Cron表达式:https://www.cnblogs.com/junrong624/p/4239517.html

Cron表达式在线生成:https://www.bejson.com/othertools/cron/

posted on 2021-03-08 22:00  harrietszhang  阅读(53)  评论(0编辑  收藏  举报