springboot schedule
来源:互联网 发布:小学同步教学软件 编辑:程序博客网 时间:2024/06/10 01:22
1.在application.properties配置文件中添加
#延迟5秒
jobs.fixedDelay=5000
#每隔2秒
jobs.cron=*/2 * * * * ?
2.新建一个ScheduleTask类
import java.text.SimpleDateFormat;import java.util.Date;import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;@Componentpublic class ScheduleTask { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @Scheduled(fixedDelayString = "${jobs.fixedDelay}") public void getTask1() { System.out.println("延迟5秒,当前时间:" + dateFormat.format(new Date())); } @Scheduled(cron = "${jobs.cron}") public void getTask2() { System.out.println("每隔2秒执行一次,当前时间:" + dateFormat.format(new Date())); }}
3.在springboot启动类中添加启动schedule注解,如下import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableSchedulingpublic class SpringbootApplication { public static void main(String[] args) { SpringApplication app=new SpringApplication(SpringbootApplication.class); app.run(args); }}
4.启动之后效果如下
阅读全文
0 0
- springboot schedule
- SpringBoot Schedule 配置
- SpringBoot Schedule 配置
- SpringBoot-@Schedule定时任务
- SpringBoot Schedule 配置
- Springboot使用定时任务,Spring Schedule
- Springboot使用定时任务,Spring Schedule
- SpringBoot学习-(十九)SpringBoot定时器#Schedule
- Schedule
- schedule
- schedule
- schedule()
- schedule
- schedule
- Schedule
- Schedule
- SpringBoot的定时任务两种(Spring Schedule 与 Quartz 整合 )实现
- springboot
- 程序的内核态和用户态
- 使用Ambari快速部署Hadoop大数据环境
- 写给前端工程师的理论基础(4)--详解SSL
- 在字符串中找出连续最长的数字串
- 机器学习学习笔记.day1
- springboot schedule
- Android控件之ViewFlipper
- 绕过htaccess的限制工具-HTExploit
- 51NOD1277 字符串中的最大值
- Codeforces 854 A Fraction
- 使用@WebServlet配置loadOnStartup的时候不起作用的解决方法
- Quartz应用与集群原理分析
- Redis常用命令总结,建议收藏备用
- Python面向对象(基础整理)