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 ...
随机推荐
- Bzoj3441 乌鸦喝水
Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 258 Solved: 97 Description [题目背景] 一只乌鸦在自娱自乐,它在面 ...
- codefoeces 671 problem D
D. Roads in Yusland standard output Mayor of Yusland just won the lottery and decided to spent money ...
- autoKeras入门
测试本地mnist数据集 图片只用500张,450张做train与50张test, 代码如下: # conding:utf-8 import os os.environ[' import numpy ...
- vCard
vCard 在翻阅dottoro的时候,在附录(appendix)的js部分,注意到一个叫vCard的部分,能单独列出来,可能是比较重要的,至少是比较独立的部分,但是以前从未听说或者了解过这一部分,如 ...
- SSH Secure Shell 无法登录:server responded "algorithm negotiation failed”
SSH Secure Shell Client 连接 ubuntu系统报错 修改ssh的配置文件 /etc/ssh/sshd_config在配置文件中添加: Ciphers aes128-cbc,ae ...
- ccf-I’m stuck!
给定一个R行C列的地图,地图的每一个方格可能是'#', '+', '-', '|', '.', 'S', 'T'七个字符中的一个,分别表示如下意思: '#': 任何时候玩家都不能移动到此方格: ' ...
- Selenium2+python自动化59-数据驱动(ddt)【转载】
前言 在设计用例的时候,有些用例只是参数数据的输入不一样,比如登录这个功能,操作过程但是一样的.如果用例重复去写操作过程会增加代码量,对应这种多组数据的测试用例,可以用数据驱动设计模式,一组数据对应一 ...
- node.js的全局变量的注意
在node.js中,如果一个变量没有用var来声明,就会变为全局变量: 看如下代码: 1)6.js function myadd(a) { return a+abc; } function conta ...
- times、 time、clock函数说明
sysconf( _SC_CLK_TCK ) 功能 获取系统的 时钟滴答的频率. clock_gettime() clock()返回的是各个线程运行cpu时间的和, 返回值一直都是0. 定义函数: ...
- CentOS6.8-minimal安装gnome桌面 安装NVC远程桌面连接
https://blog.csdn.net/nimasike/article/details/72844403