SpringBoot-@Schedule定时任务
来源:互联网 发布:淘宝装修服务市场 编辑:程序博客网 时间:2024/05/18 09:58
SpringBoot定时任务
修改程序入口, 添加开启定时任务的注解
@SpringBootApplication@EnableSchedulingpublic class SpringbootScheduleApplication { public static void main(String[] args) { SpringApplication.run(SpringbootScheduleApplication.class, args); }}
编写定时任务类@Component进行注解扫面
@Componentpublic class ScheduleTask { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 3000) public void reportCurrentTime(){ System.out.println("当前时间:" + dateFormat.format(new Date())); }}
程序将在启动后每3秒执行
@Scheduled(fixedRate = 3000):定时器将在每隔3秒执行
@Schedule(fixedDelay = 3000):定时器将在延迟3秒后每隔3秒执行
@Schedule(initialDelay = 1000, fiexdDelay = 3000):定时器将在1秒后每隔3秒执行
@Schedule(cron = “* * * * * ?”)
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素。 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天(星期)(1~7 1=SUN 或 SUN,MON,TUE,WED,THU,FRI,SAT) 7.年份(1970-2099)
@Componentpublic class ScheduleTask { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedRate = 3000) public void reportCurrentTime(){ System.out.println("当前时间:" + dateFormat.format(new Date())); } //第一次延迟1秒执行,当执行完后3秒再执行 @Scheduled(initialDelay = 1000, fixedDelay = 3000) public void timerInit() { System.out.println("init : "+dateFormat.format(new Date())); } //每天19点50分50秒时执行 @Scheduled(cron = "50 50 19 * * ?") public void timerCron() { System.out.println("current time : "+ dateFormat.format(new Date())); }}
1 0
- SpringBoot-@Schedule定时任务
- Springboot使用定时任务,Spring Schedule
- Springboot使用定时任务,Spring Schedule
- spring schedule定时任务
- spring定时任务@schedule
- spring schedule定时任务
- SpringBoot的定时任务两种(Spring Schedule 与 Quartz 整合 )实现
- SpringBoot定时任务说明
- springboot定时任务
- springboot(九):定时任务
- springboot(九):定时任务
- springboot 定时任务
- SpringBoot定时任务SchedulingTasks
- SpringBoot 定时任务
- SpringBoot 定时任务
- SpringBoot 定时任务
- springboot (7) 定时任务
- SpringBoot定时任务
- Hibernate框架初学笔记
- Problem B: 求个最大值
- PART 4
- Divide Two Integers
- elasticsearch 组合查询
- SpringBoot-@Schedule定时任务
- windows配置环境变量无效
- python接口调用已训练好的caffe模型测试分类
- 【转】ionic run android 成功launch success,但是genymotion虚拟机没有显示
- Spring源码学习第一节
- Problem C: 数量的类模板
- [C++]条件编译——#if #ifdef 的作用
- 做项目遇到的种种问题
- Java基础——内部类