quartz与spring boot-最简模式
多年前使用过quartz,今天又需要再用,而且是在spring boot框架下。很神奇,spring也是十年前用过的。
这里仅记录下完成的最快速和简单的操作,高级的使用以后有空弄明白了再写:
1、增加maven引用
<!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
2、编写任务代码:按自己要求编写类即可,每个任务做好标注@Scheduled(...)
package com.my.task; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import java.text.SimpleDateFormat;
import java.util.Date; @Component
@Configurable
@EnableScheduling
public class HappyBirthday { /**
* 使用spring 内置slf4j日志对象
*/
private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass()); /**
* 30秒间隔启动一次任务
*/
@Scheduled(fixedRate = 1000 * 30)
public void reportCurrentTime(){
logger.info ("Scheduling Tasks Examples: The time is now " + dateFormat ().format (new Date ()));
} /**
* 每分钟启动一次任务
*/
@Scheduled(cron = "0 */1 * * * * ")
public void reportCurrentByCron(){
logger.info ("Scheduling Tasks Examples By Cron: The time is now " + dateFormat ().format (new Date()));
} private SimpleDateFormat dateFormat(){
return new SimpleDateFormat ("HH:mm:ss");
}
}
3、done
quartz与spring boot-最简模式的更多相关文章
- Intellij IDEA Spring Boot 项目Debug模式启动缓慢问题
问题 Intellij IDEA Spring Boot 项目Debug模式启动缓慢 环境 os: windows10 idea :2018.1 解决方法 去除所有断点就正常了,很诡异,原因未知.
- Quartz与Spring Boot集成使用
上次自己搭建Quartz已经是几年前的事了,这次项目中需要定时任务,需要支持集群部署,想到比较轻量级的定时任务框架就是Quartz,于是来一波. 版本说明 通过搜索引擎很容易找到其官网,来到Docum ...
- 【Quartz】Spring Boot使用properties文件配置Quartz
(1)在resource目录下新建quartz.properties文件 #============================================================== ...
- Spring - Spring Boot - Thymeleaf - textual 模式
概述 thymeleaf 的 text 模式简单使用 过程会比较啰嗦, 需要结论的同学, 可以直接到底部去寻找 背景 想尝试做一个简单的 模板工具 目的 自动生成一些简单的 重复文本 思路 尽量简单 ...
- Spring/Spring boot正确集成Quartz及解决@Autowired失效问题
周五检查以前Spring boot集成Quartz项目的时候,发现配置错误,因此通过阅读源码的方式,探索Spring正确集成Quartz的方式. 问题发现 检查去年的项目代码,发现关于QuartzJo ...
- Spring Boot 定时任务 Quartz 使用教程
Quartz是一个完全由java编写的开源作业调度框架,他使用非常简单.本章主要讲解 Quartz在Spring Boot 中的使用. 快速集成 Quartz 介绍 Quartz 几个主要技术点 Qu ...
- 2019-04-05 Spring Boot学习记录
1. 使用步骤 ① 在pom.xml 增加父级依赖(spring-boot-starter-parent) ② 增加项目起步依赖,如spring-boot-starter-web ③ 配置JDK版本插 ...
- Spring Boot文档
本文来自于springboot官方文档 地址:https://docs.spring.io/spring-boot/docs/current/reference/html/ Spring Boot参考 ...
- 20191127 Spring Boot官方文档学习(4.18-4.24)
4.18.JTA的分布式事务 通过使用Atomikos或Bitronix嵌入式事务管理器,Spring Boot支持跨多个XA资源的分布式JTA事务.部署到合适的Java EE应用程序服务器时,还支持 ...
- 在Spring Boot启动后执行指定代码
在开发时有时候需要在整个应用开始运行时执行一些特定代码,比如初始化环境,准备测试数据等等. 在Spring中可以通过ApplicationListener来实现相关的功能,不过在配合Spring Bo ...
随机推荐
- 洛谷P3375 [模板]KMP字符串匹配
To 洛谷.3375 KMP字符串匹配 题目描述 如题,给出两个字符串s1和s2,其中s2为s1的子串,求出s2在s1中所有出现的位置. 为了减少骗分的情况,接下来还要输出子串的前缀数组next.如果 ...
- JS RegExp类型
用来定义正则表达式的类型, 1. 通常情况下,我们可以直接用字面量形式来定义正则表达式,格式如下: var expression = /pattern/flags pattern为正则表达式 flag ...
- RequireJs 的 使用
为什么使用requirejs: 1.有效的防止命名的冲突 2.声明不同js之间的依赖 3.可以让我们的代码以模块化的方式组织 用法: 1.创建一个入口文件main.js(自己随便命名) 然后引入req ...
- Linux Performance Profiling & Visualization
https://github.com/figozhang/CLK/tree/master/CLK2016 http://www.linuxep.com/
- 360se打开慢,lsass 过高 , cpu温度上升
rd /s /q "%AppData%\Roaming\Microsoft\Protect" rem C:\Users\Administrator\AppData\Roaming\ ...
- Unity3D性能优化最佳实践(四)资源审查
Asset auditing - 资源审查 许多项目发生效能问题的真正原因只是由于人员操作不当或是试东试西,而不小心改到导入设定影响到导入的资源.(例如最近的gitlab惨案) 对于较大规模的项目,最 ...
- curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate.报错
curl https 网站 出现报错 解决办法: You can use the domain name as usual but override the resolver like so: cur ...
- Java利用ShutDownHook关闭系统资源
Java关闭钩子 在Java程序中能够通过加入关闭钩子,实如今程序退出时关闭资源的功能. 使用Runtime.addShutdownHook(Thread hook)向JVM加入关闭钩子 public ...
- 类中添加log4j日志
在编写代码的时候需要随时查看工作日志,查看工作日志的好处就是随时能检查出错误.所以我一般就需要在编写代码的前期添加工作日志,以便更好的查看相关错误输出. 以一个springmvc小demo为例子 主 ...
- Python内置的urllib模块不支持https协议的解决办法
Django站点使用django_cas接入SSO(单点登录系统),配置完成后登录,抛出“urlopen error unknown url type: https”异常.寻根朔源发现是python内 ...