当前位置:网站首页>定时任务 corn
定时任务 corn
2022-07-30 14:40:00 【努力学习,努力爱你!】
corn表达式
语法:秒 分 时 日 月 周 年(Spring 不支持)
http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.htm
生成工具
https://www.toolscat.com/
特殊字符:
,:枚举;
(cron=“7,9,23 * * * * ?”):任意时刻的 7,9,23 秒启动这个任务;
-:范围:
(cron=“7-20 * * * * ?”):任意时刻的 7-20 秒之间,每秒启动一次
:任意;
指定位置的任意时刻都可以
/:步长;
(cron=“7/5 * * * * ?”):第 7 秒启动,每 5 秒一次;
(cron="/5 * * * * ?“):任意秒启动,每 5 秒一次;
?:(出现在日和周几的位置):为了防止日和周冲突,在周和日上如果要写通配符使用?
(cron=”* * * 1 * ?“):每月的 1 号,启动这个任务;
L:(出现在日和周的位置)”,
last:最后一个
(cron=”* * * ? * 3L"):每月的最后一个周二
W:
Work Day:工作日
(cron=“* * * W * ?”):每个月的工作日触发
(cron=“* * * LW * ?”):每个月的最后一个工作日触发
#:第几个
(cron=“* * * ? * 5#2”):每个月的第 2 个周
示例
| Expression* | Meaning |
|---|---|
| 0 0 12 * * ? | Fire at 12pm (noon) every day |
| 0 15 10 ? * * | Fire at 10:15am every day |
| 0 15 10 * * ? | Fire at 10:15am every day |
| 0 15 10 * * ? * | Fire at 10:15am every day |
| 0 15 10 * * ?2005 | Fire at 10:15am every day during the year 2005 |
| 0 * 14 * * ? | Fire every minute starting at 2pm and ending at 2:59pm, every day |
| 0 0/5 14 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day |
| 0 0/5 14,18 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day |
| 0 0-5 14 * * ? | Fire every minute starting at 2pm and ending at 2:05pm, every day |
| 0 10,44 14 ? 3 WED | Fire at 2:10pm and at 2:44pm every Wednesdayin the month of March. |
| 0 15 10 ? * MON-FRI | Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday |
| 0 15 10 15 * ? | Fire at 10:15am on the 15th day of every month |
| 0 15 10 L * ? | Fire at 10:15am on the last day of every month |
| 0 15 10 L-2 * ? | Fire at 10:15am on the 2nd-to-last last day of every month |
| 0 15 10 ? * 6L | Fire at 10:15am on the last Friday of every month |
| 0 15 10 ? * 6L | Fire at 10:15am on the last Friday of every month |
| 0 15 10 ? * 6L 2002-2005 | Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005 |
| 0 15 10 ? * 6#3 | Fire at 10:15am on the third Friday of every month |
| 0 0 12 1/5 * ? | Fire at 12pm (noon) every 5 days every month, starting on the first day of the month. |
| 0 11 11 11 11 ? | Fire every November 11th at 11:11am |
使用
package com.jhj.gulimall.ssoclient.scheduled;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@EnableScheduling //开启定时任务
@EnableAsync //开启异步
public class HelloSchedule {
//与cron的区别
//spring 只允许6位 不允许年
// 在周几的位置 1-7表示周一到周日 :MON-SUN
/** *定时任务不应该阻塞 默认是阻塞的 *以异步方式执行 *支持定时任务线程池 配置 spring.task.scheduling.pool.size=5 不太好用 * 让定时任务加入线程 在类上使用@EnableAsync 在方法上使用@Async **/
@Async
@Scheduled(cron = "* * * * * ?")
public void Hello(){
System.out.println("hello");
}
}
作者声明
如有问题,欢迎指正!
边栏推荐
- Huawei issues another summoning order for "Genius Boys"!He, who had given up an annual salary of 3.6 million, also made his debut
- canal抓取数据
- Alluxio为Presto赋能跨云的自助服务能力
- 关于华为应用市场审核App无法启动的问题
- Flink real-time data warehouse completed
- Go to Tencent for an interview and let people turn left directly: I don't know idempotency!
- Installing and Uninstalling MySQL on Mac
- 新时代背景下智慧城市的建设与5G技术有何关联
- EasyV数字孪生流域|宁波智慧水利整体智治综合应用
- Still saying software testing doesn't have a midlife crisis?9 years of test engineers were eliminated
猜你喜欢

瑞吉外卖项目实战Day02

1222. 可以攻击国王的皇后-力扣双百代码

Our company has used gateway services for 6 years, dynamic routing, authentication, current limiting, etc., a stable batch!

5G-based Warehousing Informatization Solution 2022

5. DOM

Metaverse Post Office AI space-themed series of digital collections will be launched at 10:00 on July 30th "Yuanyou Digital Collection"

一文读懂网络效应对Web3的重要意义

【元胞自动机】基于元胞自动机模拟生命演化、病毒感染等实例附matlab代码

Container sorting case

基于FPGA的DDS任意波形输出
随机推荐
第十一章 api mgmnt API 参考
分布式限流 redission RRateLimiter 的使用及原理
71页全域旅游综合整体解决方案2021 ppt
CVE-2022-33891 Apache Spark 命令注入复现
华为再发「天才少年」召集令!曾放弃360万年薪的他也来首秀
瑞吉外卖项目实战Day02
一文读懂网络效应对Web3的重要意义
5G-based Warehousing Informatization Solution 2022
惊艳!京东T8纯手码的Redis核心原理手册,基础与源码齐下
怎么判断两个字符串是否相等?
Start learning C language
JUC common thread pool source learning 02 ( ThreadPoolExecutor thread pool )
Allure Advanced - Dynamically Generate Report Content
【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码
自动化办公|办公软件和亿图脑图MindMaster快捷键
Get the Google Advertising ID as a unique identifier
Some thoughts on String
English语法_不定代词 - both / either / neither
国内数字藏品的乱象与未来
CS内网横向移动 模拟渗透实操 超详细