当前位置:网站首页>quartz簡單用法及其es-job
quartz簡單用法及其es-job
2022-07-22 02:45:00 【禿頭俠客】
基礎理論
小頂堆
堆是一個完全二叉樹(出過最後都是滿二叉,最後一排葉子節點靠左邊),且
子節點都比葉子節點大或者小。
按照這個特性,我們將任務放入後最小的會跑到頂部,我們取走即可。(小頂堆)
我們使用一個數組,數組中某一元素的父節點比特置處於該節點比特置除以二的比特置,將插入的任務至於尾部,一直找父節點,找到它對應的比特置即可。
時間輪
1.鏈錶或者數組實現時間輪:while-true-sleep
遍曆數組,每個下標放置一個鏈錶,鏈錶節點放置任務,遍曆到了就取出執行。
2.round型時間輪
任務上記錄一個round,遍曆到了就round减一,為0時取出執行。
缺點:需要遍曆所有的任務,效率較低。
3.分層時間輪(常用的方式)
使用多個不同時間維度的輪:天輪:記錄幾點執行;月輪記錄幾號執行。
月輪遍曆到了,將任務取出放到天輪裏面,即可實現幾號幾點執行。
quartz用法
- Job 任務
Job就是你想要實現的任務類,每一個Job必須實現org.quartz.job接口,且只需要實現接口定義的execute()方法。 - Trigger觸發器
通過觸發器來觸發任務 - 調度器Scheduler
傳入任務和觸發器執行
job和trigger通過建造者模式來創建。
demo
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class MyJob implements Job {
private String name;
public void setName(String name) {
this.name = name;
}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
JobDataMap jobDataMapT = context.getTrigger().getJobDataMap();
System.out.println("我是"+name+"GAME"+jobDataMap.getString("game")+jobDataMapT.getString("sport")+new Date());
jobDataMap.put("i",jobDataMap.getInt("i")+1);
System.out.println("執行的第"+jobDataMap.get("i"));
}
}
public class TestJob {
public static void main(String[] args) {
//jobdetail
JobDetail jobDetail = JobBuilder
.newJob(MyJob.class).withIdentity("myjob","jobTest")
.usingJobData("name", "fengqiao")
.usingJobData("game","lol")
.usingJobData("i",1)
.build();
//trigger
SimpleTrigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("mytrigger", "triggerTest")
.withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(2).repeatForever())
.usingJobData("sport","bike")
.build();
try {
//調度器
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.scheduleJob(jobDetail, trigger);
scheduler.start();
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
}
整合springboot
參考此篇文章 quartz
es-job
請參考這兩篇文章
https://blog.csdn.net/zxylwj/article/details/102782972
https://blog.csdn.net/LOVELONG8808/article/details/80351687
边栏推荐
- Grafana visual configuration chart table
- grafana可视化配置图表table
- 云原生时代,开发者应具备这5大能力
- [development tutorial 6] AI voice face recognition (Conference recorder / face punch card machine) - serial port
- 网络安全(4)
- H3C交换机查看相关的命令
- three hundred and thirteen billion one hundred and thirty-one million three hundred and thirteen thousand one hundred and twenty-three
- 一篇论文8778个作者:人均写5个字,署名用了17页
- Number of pairs (dynamic open point)
- 博士申请 | 香港城市大学刘晨老师组招收机器学习方向全奖博士/博后/硕士/RA...
猜你喜欢
别乱用UUID了,自增ID和UUID性能差距你测试过吗?
已解决(selenium操作火狐浏览器报错)TypeError: __init__() got an unexpected keyword argument ‘firefox_options‘
Nature | 杨祎等揭示宿主内进化或可导致肠道共生菌致病
基于深度神经网络的中药材识别
有一说一,要搞明白优惠券架构是如何演化的,只需10张图!
Leetcode 104. Maximum depth of binary tree
静态路由原理与配置
网络层协议介绍
OpenMMLAB系列框架解读(基于PyTorch)
SVD singular value decomposition matrix compression
随机推荐
我,AI博士生,在线众筹研究主题
[Development Tutorial 4] crazy shell · humanoid hip-hop robot PC upper computer online debugging
web安全入门-TCP压力测试与防御
阿里云技术专家杨泽强:弹性计算云上可观测能力构建
利用二分寻找峰值
Pd 使用手册
ASUS Adu 14 Pro is equipped with the new generation 12 core standard voltage processor
【微信小程序】textarea多行输入框(80/100)
Leetcode 104. Maximum depth of binary tree
In the cloud native era, developers should have these five capabilities
辛丑年之万家灯火
Chapter 2 software process and thought section 1 Foundation
代码表征预训练语言模型学习指南:原理、分析和代码
[development tutorial 6] AI voice face recognition (Conference recorder / face punch card machine) - serial port
Leetcode 111. Minimum depth of binary tree
小米12S Ultra产品力这么强老外却买不到 雷军:先专心做好中国市场
网络地址转换(NAT)
CTF problem solving ideas
QT | QT project documents Detailed explanation of pro file
FastDFS高可用使用介绍