spring-Scheduled
来源:互联网 发布:中国大学生网络党课 编辑:程序博客网 时间:2024/05/24 07:06
SpringBoot
1、开启定时任务
1.如果加在入口类上,表示开启全部的定时任务2.如果加在业务类上,表示开启这个类内部的的定时任务
@SpringBootApplication@EnableSchedulingpublic class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); }}
2.创建定时器类
1.类上添加@Component ,将业务类交给IOC容器 2.方法上添加@Scheduled,定制定时策略
@Componentpublic class Timer { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Scheduled(cron="0 0/1 * * * ?") //每分钟执行一次 public void statusCheck() { logger.info("每分钟执行一次。"); } @Scheduled(fixedRate=20000) public void testTasks() { logger.info("每20秒执行一次。"); } }
3.定时策略
Scheduled有三个参数
CRON:使用corn表达式fixedDelay:固定触发间隔fixedRate:固定触发频率initialDelay:首次延时
区别如图:
参考
http://blog.csdn.net/applebomb/article/details/52400154
阅读全文
0 0
- spring scheduled
- Spring @Scheduled
- Spring-@Scheduled
- spring-Scheduled
- spring配置scheduled job
- spring @Scheduled 并发执行
- Spring中的@Scheduled
- Spring注解定时器@Scheduled
- spring @scheduled并发
- spring定时器(@Scheduled)
- Spring任务调度scheduled
- Spring @Scheduled 注解
- Spring 定时任务 @Scheduled
- spring scheduled定时任务
- spring @Scheduled 定时器
- spring @Scheduled cron表达式
- Spring @Scheduled应用解析
- Spring定时任务(@Scheduled)
- Java多线程--Exchanger(一)
- 使用SSM框架整合时,无法创建XXXXBean
- Asp.Net MVC 5使用Identity之简单的注册和登陆
- 小白的踩坑记录——socket.io-解决多进程
- 动态内存开辟
- spring-Scheduled
- 对称的二叉树
- Java多线程--Exchanger(二)
- Oracle之JAVA数据导出工具-yellowcong
- 欢迎使用CSDN-markdown编辑器
- CentOS 中 nginx 负载均衡和反向代理的搭建 阅读 2449
- 高逼格Mac应用程序、软件分享【主要面向开发者和设计师】
- vb在串口通信中运行时错误‘380’无效属性值
- pip install scikit-image win安装错误