SpringBoot整合Quartz定时任务
记录一个SpringBoot 整合 Quartz 的Demo实例
POM.XML文件
<!-- 定时器任务 quartz需要导入的坐标 -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.5</version>
</dependency>
类似于控制器代码:
package com.xiaowu.quartz.demo; import java.util.Date; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; /***
*
* Quartz设置项目全局的定时任务
*
* @Component注解的意义 泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。一般公共的方法我会用上这个注解
*
*
* @author WQ
*
*/
@Component
public class QuartzDemo { @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
public void work() throws Exception {
System.out.println("执行调度任务:"+new Date());
} @Scheduled(fixedRate = 5000)//每5秒执行一次
public void play() throws Exception {
System.out.println("执行Quartz定时器任务:"+new Date());
} @Scheduled(cron = "0/2 * * * * ?") //每2秒执行一次
public void doSomething() throws Exception {
System.out.println("每2秒执行一个的定时任务:"+new Date());
} @Scheduled(cron = "0 0 0/1 * * ? ") // 每一小时执行一次
public void goWork() throws Exception {
System.out.println("每一小时执行一次的定时任务:"+new Date());
} }
启动SpringBoot项目,即可。
public static void main(String[] args) {
SpringApplication.run(Chapter1Application.class, args);
}
,截图如下:
SpringBoot整合Quartz定时任务的更多相关文章
- SpringBoot整合Quartz定时任务 系统job Spring Boot教程 调度任务
原文地址:https://www.cnblogs.com/allalongx/p/8477368.html 构建工程 创建一个Springboot工程,在它的程序入口加上@EnableScheduli ...
- SpringBoot整合Quartz定时任务(持久化到数据库)
背景 最近在做项目,项目中有个需求:需要使用定时任务,这个定时任务需要即时生效.查看Quartz官网之后发现:Quartz提供两种基本作业存储类型: RAMJobStore :RAM也就是内存,默认情 ...
- SpringBoot整合Quartz定时任务 的简单实例
POM.XML文件 <!-- 定时器任务 quartz需要导入的坐标 --> <dependency> <groupId>org.quartz-scheduler& ...
- SpringBoot整合Quartz定时任务 的简单实例 2
(1)什么是Quartz?(2)Quartz的特点:(3)Quartz专用词汇说明:(4)Quartz任务调度基本实现原理: 接下来看下具体的内容: (1)什么是Quartz? Quartz是一个完全 ...
- SpringBoot整合Quartz及log4j实例
SpringBoot整合Quartz及log4j实例 因为之前项目中经常会做一些定时Job的东西,所以在此记录一下,目前项目中已经使用elastic-job,这个能相对比Quartz更加简单方便一些, ...
- Spring整合Quartz定时任务执行2次,Spring定时任务执行2次
Spring整合Quartz定时任务执行2次,Spring定时任务执行2次 >>>>>>>>>>>>>>>&g ...
- Spring整合Quartz定时任务 在集群、分布式系统中的应用(Mysql数据库环境)
Spring整合Quartz定时任务 在集群.分布式系统中的应用(Mysql数据库环境) 转载:http://www.cnblogs.com/jiafuwei/p/6145280.html 单个Q ...
- SpringBoot整合Quartz作为调度中心完整实用例子
因为想要做一个类似于调度中心的东西,定时执行一些Job(通常是一些自定义程序或者可执行的jar包),搭了一个例子,总结了前辈们的相关经验和自己的一些理解,如有雷同或不当之处,望各位大佬见谅和帮忙指正. ...
- springboot整合@Scheduled定时任务的使用
1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...
随机推荐
- php session 阻塞 过期不自动清除session文件
php默认session session_start后,php就会打开session文件,然后同一时间用户再用那个session_id访问,就会被前面那个请求阻塞直到前面一个访问结束才会释放文件在使 ...
- NYOJ 211 Cow Contest (弗洛伊德+传递闭包 )
title: Cow Contest 弗洛伊德+传递闭包 nyoj211 tags: [弗洛伊德,传递闭包] 题目链接 描述 N (1 ≤ N ≤ 100) cows, conveniently nu ...
- bzoj 1861 splay
就是裸地splay,然后自己写的不是特别好,tle了,最近时间比较紧迫,有时间了改下,在此记录 另附转载pascal AC代码最下面 /******************************** ...
- GridPanel分页条插件
GridPanel的分页条没有设置当前页显示条数的功能,会不大方便 主要是抄袭的http://www.cnblogs.com/badwps/archive/2011/04/15/2016440.htm ...
- Linux : select()详解 和 实现原理【转】
转自:http://blog.csdn.net/huntinux/article/details/39289317 原文:http://blog.csdn.net/boboiask/article/d ...
- CSS边框属性
边框 圆角 border-radius border-top-left-radius border-top-right-radius border-bottom-left-radlius border ...
- 怎么在32位windows系统上搭建爬虫框架scrapy?
禁止转载: 自学python,然后搭建爬虫框架scrapy.费了我一上午的心血.终于搭建成功,以防以后忘记搭建流程,特此撰写此贴,开写 ******************************** ...
- magento 搬家
1.删除浏览记录: log_customer log_visitor log_visitor_info log_url log_url_info log_quote report_viewed_pro ...
- asp.net数据类型--泛型
asp.net有很多的数据类型,同时c#等均是强数据类型,在使用的过程,存在因数据类型不一致,在编译时通过,在使用过程中出错的情况,因此从2.0起,增加泛型这种类型.这种类型,在定义时不指定类型,而在 ...
- CF 1006B Polycarp's Practice【贪心】
Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a1,a ...