当前位置:网站首页>一文了解定时任务
一文了解定时任务
2022-07-17 05:02:00 【小新爱编程】

什么是定时任务?
定时任务,简要说明就是在指定时间内触发执行某个动作。类似于我们今天晚上12要买个东西,然后你需要定一个闹钟提醒你,告诉你12点你需要买个东西,这个闹钟定时提醒你,就是一种定时任务。
定时任务的应用场景
下订单:30分钟以内实现付款功能 。
下订单:开始定时任务;是否付款,付款,完成订单;没有付款,取消订单。
数据库:定时清理,统计。
使用Schedule实现定时任务
Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每
一个域代表一个含义,Cron有如下两种语法格式:
(1) Seconds Minutes Hours DayofMonth Month DayofWeek Year
(2)Seconds Minutes Hours DayofMonth Month DayofWeek
| 字段 | 允许值 | 允许的特殊字 |
|---|---|---|
| 秒 | – 0~59的整数 | , - * / 四个字符 |
| 分 | 0~59的整数 | , - * / 四个字符 |
| 小时 | 0~23的整数 | , - * / 四个字符 |
| 日期 | 1~31的整数(但是你需要考虑你月的天数) | ,- * ? / L W C 八个字符 |
| 月份 | 1~12的整数或者 JAN-DEC | , - * / 四个字符 |
| 星期 | 1~7的整数或者 SUN-SAT(1=SUN) | , - * ? / L C # 八个字符 |
| 年(可选,留空) | 1970~2099 | , - * / 四个字符 |
例子
@Configuration
@EnableScheduling
public class MyJobTest {
@Scheduled(cron="0/2 * * * * *")
public void task(){
System.out.println("时间:"+
LocalDateTime.now());
}
}
使用quartz实现定时任务
1、引入jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starterquartz</artifactId>
</dependency>
边栏推荐
- Quickly master Mipi development strategy
- Hyperlink implementation post submission
- Mongo Db单机版的安装和快速使用
- Emqx pressure test tread pit for your reference
- EasyExcel简单使用
- Extreme video compression using the pellet toolbox
- 服务端接口测试-接口测试的测试点【杭州多测师】【杭州多测师_王sir】
- 渗透测试 10 --- 扫描 web目录 (dirb、wfuzz、wpscan、nikto)
- [Unity] Input. Index of gettouch[index]
- MySQL one line to many lines (split according to specific symbols)
猜你喜欢

Blessing for the elderly popular short video wechat applet source code download support traffic master

shardingsphere内核原理

MySQL必知必会!!!看这一篇就足够了!!!
![[FPGA tutorial case 26] realize the basic operation of decimals through Verilog in FPGA](/img/94/a123d212ccde207395d72e9563012c.png)
[FPGA tutorial case 26] realize the basic operation of decimals through Verilog in FPGA
![Service end interface test - test point of interface test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]](/img/62/ae0d6f5654c1352437ac99947d25e4.png)
Service end interface test - test point of interface test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]

EMQX 压力测试踩得坑供大家参考

PowerDesigner displays comment comments

Eureka, take advantage of the tens of millions of daily visits!

OLTP 负载性能优化实践
![Fudan micro fmql (domestic zynq) [PS of IAR bare metal development] - non byte aligned access](/img/e7/8349da2c240ac8f51524e5e51bd4d6.png)
Fudan micro fmql (domestic zynq) [PS of IAR bare metal development] - non byte aligned access
随机推荐
知识图谱de构建与应用(七):大规模知识图谱预训练
Easyexcel easy to use
tidb 学习
TCP/IP 协议
Declaration and definition of template class
[论文精读]BERT
力扣刷题02(三数之和+最大子序和+二叉树最近公共祖先)
[vuforia] simple logic of image recognition
And predicts that nerf will eventually replace deepfake
Money making master applet [latest version 5.9.9] mall / instant withdrawal of commission / distribution promotion / phone recharge / is meituan hungry for takeout
Sphinx遇到的问题
【英雄哥七月集训】第 16天:队列
Extreme video compression using the pellet toolbox
简洁UI好玩的文字转换emoji表情微信小程序支持句子词语转换_源码
shardingproxy分库分表实战及同类产品对比
Beidou clock server (NTP server) makes the time of college entrance examination more accurate
Warriors of the Visual Studio, Assemble! (Visual Studio的勇士们,汇编吧!) 原创 2009年07月12日 19:40:00 标签:汇编 /mic
Efficient insertion of references in word with thousands of words and many pictures
Service end interface test - test point of interface test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
Wechat applet source code of high imitation Netease cloud music UI