当前位置:网站首页>一文了解定时任务
一文了解定时任务
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>
边栏推荐
- Freshman task-5
- shardingsphere内核原理
- 模板类的声明和定义
- Only when the data analysis report is written in this way can we really understand the data
- Mongo Db单机版的安装和快速使用
- Database and the future of open source
- 删除快照出现:删除快照时出错: 字典问题
- PHP array_filter去空保留0,false
- [TA frost wolf _may - "hundred people plan"] art 2.1 DCC tool chain and engine tool chain
- Masm32 writer
猜你喜欢

Reproduction of XOR and encryption decryption

itext修改pdf文字
[论文精读]BERT

Emqx pressure test tread pit for your reference

Mongo Db单机版的安装和快速使用

Simple UI funny text conversion Emoji expression wechat applet supports sentence word conversion_ Source code

新生任务-5
![[Lipschitz] simulation of Lipschitz Lipschitz exponent based on MATLAB](/img/72/c69ed6e5538169c362b7b4bab36d5e.png)
[Lipschitz] simulation of Lipschitz Lipschitz exponent based on MATLAB

Unity UMP打包黑屏问题总结

C list set object de duplication LINQ de duplication with time de duplication
随机推荐
Rearrange data according to date JS
Mongo Db聚合操作和索引
Kubernetes 的监控与告警
PHP array_ Filter empty leave 0, false
An easy-to-use network liar reporting system without encrypted version source code
And predicts that nerf will eventually replace deepfake
【英雄哥七月集训】第 16天:队列
Notes on Advanced Mathematics: a conjecture about the Equivalent Infinitesimal Substitution
Record a stored procedure to batch modify the table structure
新生任务-5
Fudan micro fmql (domestic zynq) [PS of IAR bare metal development] - non byte aligned access
TiDB 性能分析和优化
Redis简介
shardingsphere内核原理
Notes on Advanced Mathematics: second derivative of composite function and curvature of solving parametric equation
[TA frost wolf \u may - hundred people plan] Figure 2.5 bump mapping
Pingcap clinic data acquisition instructions
NPM installation tutorial
Unity UMP打包黑屏問題總結
项目组暑假总结01