目录
定时任务应用场景:年度报表、秒杀商品上架、缓存统计报告
task就是spring的
一 步骤
1 引导类
加注解@EnableScheduling:开启定时任务功能
2 bean
把当前bean注入spring容器
任务上面加@Scheduled注解
package com.qing.bean;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MyBean {
//cron = "秒 分 时 日 月 星期"
//cron = "0/1 * * * * ?" :从0秒开始每1s执行一次
@Scheduled(cron = "0/1 * * * * ?")
public void print(){
System.out.println("spring task run ...");
}
}
完事了
(3 task的配置)
试一下线程前缀名