springboot实现定时任务的一种方式
参考:https://www.yoodb.com/news/detail/1205
目前觉得这种还是很好用,所以就记录。
最好新建一个项目测试:
1. pom中添加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
</dependency>
2. 启动类添加注释:@EnableScheduling
3. 配置
server:
port: 55550 #日志
logging:
file: ./logs/apple.log spring:
application:
name: asfood-apple eureka:
client:
serviceUrl:
defaultZone: http://localhost:55580/eureka/ #详情[parent/asfood]/doc_nn/cron.txt
tasktime_cron: 0/20 * 14,15 * * ?
4. 新建类
@Configuration
public class TaskTest {
private static int i = 0; /**
cron:指定cron表达式。
fixedDelay:
官方文档解释:An interval-based trigger where the interval is measured from the completion time of the previous task.
The time unit value is measured in milliseconds.
即表示从上一个任务完成开始到下一个任务开始的间隔,单位是毫秒。
fixedRate:
官方文档解释:An interval-based trigger where the interval is measured from the start time of the previous task.
The time unit value is measured in milliseconds.
即从上一个任务开始到下一个任务开始的间隔,单位是毫秒。
*/
@Scheduled(cron="${tasktime_cron}")
// @Scheduled(fixedRate=2000) // 每5分钟执行一次 5*60*1000
// @Scheduled(fixedRate=1000) // 每1s
public void dual() {
System.out.println(i++);
}
}
运行,试试? 哈哈哈,估计可以成功,里面没什么多的东西,至于cron表达式可以百度学习。
springboot实现定时任务的一种方式的更多相关文章
- SpringBoot配置定时任务的两种方式
一.导入相关的jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...
- springboot实现定时任务的两种方式
方式一:在springboot启动类上添加@EnableScheduling注解,然后创建具体的任务类,在方法上添加@Scheduled注解,并指明执行频率即可.如下: @Componentpubli ...
- SpringBoot整合Servlet的两种方式
SpringBoot整合Servlet有两种方式: 1.通过注解扫描完成Servlet组件的注册: 2.通过方法完成Servlet组件的注册: 现在简单记录一下两种方式的实现 1.通过注解扫描完成Se ...
- springboot成神之——mybatis在spring-boot中使用的几种方式
本文介绍mybatis在spring-boot中使用的几种方式 项目结构 依赖 WebConfig DemoApplication 方式一--@Select User DemoApplication ...
- SpringBoot从入门到精通二(SpringBoot整合myBatis的两种方式)
前言 通过上一章的学习,我们已经对SpringBoot有简单的入门,接下来我们深入学习一下SpringBoot,我们知道任何一个网站的数据大多数都是动态的,也就是说数据是从数据库提取出来的,而非静态数 ...
- 【SpringBoot】05.SpringBoot整合Listener的两种方式
SpringBoot整合Listener的两种方式: 1.通过注解扫描完成Listener组件的注册 创建一个类实现ServletContextListener (具体实现哪个Listener根据情况 ...
- 【SpringBoot】03.SpringBoot整合Servlet的两种方式
SpringBoot整合Servlet的两种方式: 1. 通过注解扫描完成Servlet组件注册 新建Servlet类继承HttpServlet 重写超类doGet方法 在该类使用注解@WebServ ...
- Springboot下载Excel的3种方式
Springboot下载Excel的3种方式 汇总一下浏览器下载和代码本地下载实现的3种方式. (其实一般都是在代码生成excel,然后上传到oss,然后传链接给前台,但是我好像没有实现过直接点击就能 ...
- Spring Boot 实现定时任务的 4 种方式
作者:Wan QingHua wanqhblog.top/2018/02/01/SpringBootTaskSchedule/ 定时任务实现的几种方式: Timer:这是java自带的java.uti ...
随机推荐
- java基础之bit、byte、char、String
bit 位,二进制数据0或1 byte 字节,一个字节等于8位二进制数 char 字符, String 字符串,一串字符 常见转换 1 字母 = 1byte = 8 bit 1 汉字 = 2byt ...
- QT 带有菜单项的ToolButton
QToolBar *pToolBar = new QToolBar; QToolButton *pMenuBtn = new QToolButton; pMenuBtn->setText(tr( ...
- audiojs 音频插件使用教程
audiojs 音频插件使用教程 github地址 https://kolber.github.io/audiojs/ 依赖文件 <script src="https://cdn.bo ...
- js判断是pc还是移动端
//判断pc还是移动端 var isM = function () { var ua = navigator.userAgent; /* navigator.userAgent 浏览器发送的用户代理标 ...
- hdu 1536/ hdu 1944 S-Nim(sg函数)
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Chrome Adobe flash player已过期怎么办
越来越多的朋友感受到了来自谷歌chrome新版浏览器的压力,因为有不少朋友在使用新版chrome浏览器看视频时,却出现了这样的提示:Adobe flash player已过期!怎么办啊? 有网友抱怨: ...
- mysql_异常_01_Access denied for user 'root'@'192.168.1.13' (using password: YES)
一.异常现象 使用navicat premuim 连接 虚拟机mysql数据库时 ,抛出如下错误: Access denied for user 'root'@'192.168.1.13' (usin ...
- java对Hbase的基本操作
1.新建一个普通java项目,把${hbase}/lib/目录下的jar包全部导入 2.导出jar文件如下 3.运行 注意:需要先把jar文件导入到hbase路径里去,然后运行相应的类 4.查看数据 ...
- xml获取指定节点的路径
引用自http://www.w3school.com.cn/xpath/xpath_syntax.asp XPath 语法 Previous Page Next Page XPath 使用路径表达式来 ...
- len(),range()函数
len()函数返回字符串.列表.字典.元组等长度 eg1:计算字符串的长度: >>>s='hello good boy doiido' >>>len(s) > ...