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 ...
随机推荐
- iis和apache共享80端口
Windows server 2003服务器上安装有默认 IIS 6和Apache两个服务器,IIS运行的一个.net程序,apache运行php程序,现在想让它们同时都能通过80端口访问,设置起来还 ...
- asp.net web api history and how does it work?
https://blogs.msdn.microsoft.com/zxue/2012/11/07/what-is-asp-net-web-api-and-how-does-it-work/ https ...
- Linux 基本命令___0002
来源:https://mp.weixin.qq.com/s/DmfpDfWpWRV3EDItDdYgXQ #配置vim #http://www.cnblogs.com/ma6174/archive/2 ...
- 【P1369】矩形(贪心)
蒟蒻现在连DP都做不出来了,就只能做一些XJB贪心题,这个题题目向非常友好,100的数据范围一看就是让你跑O(n^4)的做法的,然而实际上并不是那么多,大约是,额,反正要快不少. 没什么好说的,直接枚 ...
- 小组E-R图的改进 2.0版本
上图是我对我们小组的数据库E-R图的改进 我在出勤上加了一个学生留言,因为我们组在需求分析中说明了有个教师与学生通过此软件交流的功能,教师可以通过这个功能给学生留言,学生也可以通过此功能请假或者说明旷 ...
- HDU 5183 Negative and Positive (NP) (hashmap+YY)
学到了以邻接表方式建立的hashmap 题意:给你一串数a和一个数k,都有正有负,问知否能找到一对数(i,j)(i<=j)保证a [i] - a [i+1] + a [i+2] - a [i+3 ...
- Lightoj 1370 素数打表 +二分
1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Time Limit: 2 second(s) Memory Limit: 32 MB ...
- kvm 客户机系统的代码是如何运行的
一个普通的 Linux 内核有两种执行模式:内核模式(Kenerl)和用户模式 (User).为了支持带有虚拟化功能的 CPU,KVM 向 Linux 内核增加了第三种模式即客户机模式(Guest), ...
- DB2导入数据时乱码问题
1.由于导入import导入数据时乱码,一直找不到解决办法,于是就用load导入 LOAD后,发现某些表检查挂起( 原因码为 "1",所以不允许操作 SQLSTATE=57016 ...
- Ngnix学习笔记
一.Ngnix介绍 1.概念 一个强大的Web服务器软件. 2.功能 1)处理高并发的http请求. 2)作为反向代理服务器来进行负载均衡. 3)数据压缩和解压缩处理 3.优势 高性能,轻量级,内存消 ...