定时调度任务-quartz(一)
一、整体表结构一览
1.1、表名及描述

| 表名 | 描述 |
|---|---|
| QRTZ_SCHEDULER_STATE | 调度器实例 |
| QRTZ_TRIGGERS | 基础触发器 |
| QRTZ_CRON_TRIGGERS | cron表达式触发器 |
| QRTZ_SIMPLE_TRIGGERS | 简单的触发器 |
| QRTZ_FIRED_TRIGGERS | 执行过的触发器 |
| QRTZ_PAUSED_TRIGGER_GRPS | 暂停的触发器 |
| QRTZ_JOB_DETAILS | 定时调度任务详情 |
| QRTZ_LOCKS | 悲观锁(多节点部署) |
| QRTZ_CALENDARS | 日历 |
1.2、概念
quartz中三个重要概念:schedule、trigger、job
- schedule(调度器):统一调度触发器
- trigger(触发器):根据设定的规则定时触发
- job(任务):触发器触发执行的任务主体
二、各表详情
2.1、QRTZ_SCHEDULER_STATE
存储所有节点的scheduler,会定期检查scheduler是否失效,启动多个scheduler。
drop table if exists QRTZ_SCHEDULER_STATE;/*==============================================================*/
/* Table: QRTZ_SCHEDULER_STATE */
/*==============================================================*/
create table QRTZ_SCHEDULER_STATE
(SCHED_NAME varchar(120) not null comment '调度名称:配置文件',INSTANCE_NAME varchar(200) not null comment '实例名称:计算机名称',LAST_CHECKIN_TIME bigint not null comment '最后检查时间',CHECKIN_INTERVAL bigint not null comment '检查周期:配置文件',primary key (SCHED_NAME, INSTANCE_NAME)
);alter table QRTZ_SCHEDULER_STATE comment '定时任务 调度器实例';
2.2、QRTZ_TRIGGERS
添加一个触发器就记录一条,触发器的主要记录。
drop table if exists QRTZ_TRIGGERS;/*==============================================================*/
/* Table: QRTZ_TRIGGERS */
/*==============================================================*/
create table QRTZ_TRIGGERS
(SCHED_NAME varchar(120) not null comment '调度器名称',TRIGGER_NAME varchar(200) not null comment '触发器名称',TRIGGER_GROUP varchar(200) not null comment '触发器组',JOB_NAME varchar(200) not null comment 'job名称',JOB_GROUP varchar(200) not null comment 'job组',DESCRIPTION varchar(250) comment '触发器描述',NEXT_FIRE_TIME bigint comment '下一次时间(时间戳)',PREV_FIRE_TIME bigint comment '上一次时间(时间戳)',PRIORITY bigint comment '触发器优先级',TRIGGER_STATE varchar(16) not null comment '触发器状态:WAITING->ACQUIRED->PAUSED->COMPLETE->ERROR',TRIGGER_TYPE varchar(8) not null comment '触发器类型:CRON SIMPLE',START_TIME bigint not null comment '开始执行时间(时间戳)',END_TIME bigint comment '结束执行时间(时间戳)',CALENDAR_NAME varchar(200) comment '日历名称',MISFIRE_INSTR smallint comment '触发器错过时间',JOB_DATA longblob comment '触发器额外数据',primary key (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP)
);alter table QRTZ_TRIGGERS comment '定时任务 基础触发器';/*==============================================================*/
/* Index: idx_qrtz_t_j */
/*==============================================================*/
create index idx_qrtz_t_j on QRTZ_TRIGGERS
(SCHED_NAME
);/*==============================================================*/
/* Index: idx_qrtz_t_jg */
/*==============================================================*/
create index idx_qrtz_t_jg on QRTZ_TRIGGERS
(SCHED_NAME
);/*==============================================================*/
/* Index: idx_qrtz_t_c */
/*==============================================================*/
create index idx_qrtz_t_c on QRTZ_TRIGGERS
(SCHED_NAME,CALENDAR_NAME
);/*==============================================================*/
/* Index: idx_qrtz_t_g */
/*==============================================================*/
create index idx_qrtz_t_g on QRTZ_TRIGGERS
(SCHED_NAME,TRIGGER_GROUP
);/*==============================================================*/
/* Index: idx_qrtz_t_state */
/*==============================================================*/
create index idx_qrtz_t_state on QRTZ_TRIGGERS
(SCHED_NAME,TRIGGER_STATE
);/*==============================================================*/
/* Index: idx_qrtz_t_n_state */
/*==============================================================*/
create index idx_qrtz_t_n_state on QRTZ_TRIGGERS
(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE
);/*==============================================================*/
/* Index: idx_qrtz_t_n_g_state */
/*==============================================================*/
create index idx_qrtz_t_n_g_state on QRTZ_TRIGGERS
(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE
);/*==============================================================*/
/* Index: idx_qrtz_t_next_fire_time */
/*==============================================================*/
create index idx_qrtz_t_next_fire_time on QRTZ_TRIGGERS
(SCHED_NAME,NEXT_FIRE_TIME
);/*==============================================================*/
/* Index: idx_qrtz_t_nft_st */
/*==============================================================*/
create index idx_qrtz_t_nft_st on QRTZ_TRIGGERS
(SCHED_NAME,NEXT_FIRE_TIME,TRIGGER_STATE
);/*==============================================================*/
/* Index: idx_qrtz_t_nft_misfire */
/*==============================================================*/
create index idx_qrtz_t_nft_misfire on QRTZ_TRIGGERS
(SCHED_NAME,NEXT_FIRE_TIME,MISFIRE_INSTR
);/*==============================================================*/
/* Index: idx_qrtz_t_nft_st_misfire */
/*==============================================================*/
create index idx_qrtz_t_nft_st_misfire on QRTZ_TRIGGERS
(SCHED_NAME,NEXT_FIRE_TIME,TRIGGER_STATE,MISFIRE_INSTR
);/*==============================================================*/
/* Index: idx_qrtz_t_nft_st_misfire_grp */
/*==============================================================*/
create index idx_qrtz_t_nft_st_misfire_grp on QRTZ_TRIGGERS
(SCHED_NAME,TRIGGER_GROUP,NEXT_FIRE_TIME,TRIGGER_STATE,MISFIRE_INSTR
);
2.3、QRTZ_CRON_TRIGGERS
触发器是cron类型时候,会在该表中也记录一条。
drop table if exists QRTZ_CRON_TRIGGERS;/*==============================================================*/
/* Table: QRTZ_CRON_TRIGGERS */
/*==============================================================*/
create table QRTZ_CRON_TRIGGERS
(SCHED_NAME varchar(120) not null comment '调度器名称',TRIGGER_NAME varchar(200) not null comment '触发器名称',TRIGGER_GROUP varchar(200) not null comment '触发器组',CRON_EXPRESSION varchar(200) not null comment 'cron表达式',TIME_ZONE_ID varchar(80) comment '时间区',primary key (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP)
);alter table QRTZ_CRON_TRIGGERS comment '定时任务 cron触发器';
2.4、QRTZ_SIMPLE_TRIGGERS
存放简单类型Trigger的信息,包括从某个时间点开始,重复次数,间隔及已触发的次数。
drop table if exists QRTZ_SIMPLE_TRIGGERS;/*==============================================================*/
/* Table: QRTZ_SIMPLE_TRIGGERS */
/*==============================================================*/
create table QRTZ_SIMPLE_TRIGGERS
(SCHED_NAME varchar(120) not null comment '计划名称',TRIGGER_NAME varchar(200) not null comment '触发器名称',TRIGGER_GROUP varchar(200) not null comment '触发器组',REPEAT_COUNT bigint not null comment '重复次数',REPEAT_INTERVAL bigint not null comment '重复间隔ms',TIMES_TRIGGERED bigint not null comment '已触发次数',primary key (SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP)
);alter table QRTZ_SIMPLE_TRIGGERS comment '定时任务 简单的触发器';
2.5、QRTZ_FIRED_TRIGGERS
执行过的触发器,每次删除后重新添加一条新的,暂停会删除
drop table if exists QRTZ_FIRED_TRIGGERS;/*==============================================================*/
/* Table: QRTZ_FIRED_TRIGGERS */
/*==============================================================*/
create table QRTZ_FIRED_TRIGGERS
(SCHED_NAME varchar(120) not null comment '调度器名称',ENTRY_ID varchar(95) not null comment '入口ID',TRIGGER_NAME varchar(200) not null comment '触发器名称',TRIGGER_GROUP varchar(200) not null comment '触发器组',INSTANCE_NAME varchar(200) not null comment '实例名称:存储的是实例ID',FIRED_TIME bigint not null comment '执行时间(时间戳)',SCHED_TIME bigint not null comment '计划时间(时间戳)',PRIORITY bigint not null comment '优先级',STATE varchar(16) not null comment '状态:ACQUIRED->EXECUTING->删除该条记录',JOB_NAME varchar(200) comment '工作名称',JOB_GROUP varchar(200) comment '工作组',IS_NONCONCURRENT varchar(1) comment '是否同时发生',REQUESTS_RECOVERY varchar(1) comment '请求恢复:多节点使用',primary key (SCHED_NAME, ENTRY_ID)
);alter table QRTZ_FIRED_TRIGGERS comment '定时任务 执行过的触发器';/*==============================================================*/
/* Index: idx_qrtz_ft_trig_inst_name */
/*==============================================================*/
create index idx_qrtz_ft_trig_inst_name on QRTZ_FIRED_TRIGGERS
(SCHED_NAME,INSTANCE_NAME
);/*==============================================================*/
/* Index: idx_qrtz_ft_inst_job_req_rcvry */
/*==============================================================*/
create index idx_qrtz_ft_inst_job_req_rcvry on QRTZ_FIRED_TRIGGERS
(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY
);/*==============================================================*/
/* Index: idx_qrtz_ft_j_g */
/*==============================================================*/
create index idx_qrtz_ft_j_g on QRTZ_FIRED_TRIGGERS
(SCHED_NAME,JOB_NAME,JOB_GROUP
);/*==============================================================*/
/* Index: idx_qrtz_ft_jg */
/*==============================================================*/
create index idx_qrtz_ft_jg on QRTZ_FIRED_TRIGGERS
(SCHED_NAME,JOB_GROUP
);/*==============================================================*/
/* Index: idx_qrtz_ft_t_g */
/*==============================================================*/
create index idx_qrtz_ft_t_g on QRTZ_FIRED_TRIGGERS
(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP
);/*==============================================================*/
/* Index: idx_qrtz_ft_tg */
/*==============================================================*/
create index idx_qrtz_ft_tg on QRTZ_FIRED_TRIGGERS
(SCHED_NAME,TRIGGER_GROUP
);
2.6、QRTZ_PAUSED_TRIGGER_GRPS
drop table if exists QRTZ_PAUSED_TRIGGER_GRPS;/*==============================================================*/
/* Table: QRTZ_PAUSED_TRIGGER_GRPS */
/*==============================================================*/
create table QRTZ_PAUSED_TRIGGER_GRPS
(SCHED_NAME varchar(120) not null comment '调度器名称',TRIGGER_GROUP varchar(200) not null comment '触发器组',primary key (SCHED_NAME, TRIGGER_GROUP)
);alter table QRTZ_PAUSED_TRIGGER_GRPS comment '定时任务 暂停的触发器';
2.7、QRTZ_JOB_DETAILS
记录触发器执行的任务详情
drop table if exists QRTZ_JOB_DETAILS;/*==============================================================*/
/* Table: QRTZ_JOB_DETAILS */
/*==============================================================*/
create table QRTZ_JOB_DETAILS
(SCHED_NAME varchar(120) not null comment '调度器名称',JOB_NAME varchar(200) not null comment 'job名称',JOB_GROUP varchar(200) not null comment 'job组',DESCRIPTION varchar(250) comment 'jobDetails描述',JOB_CLASS_NAME varchar(250) not null comment '调度任务类名',IS_DURABLE varchar(1) not null comment '是否持久化:把该属性设置为1,quartz会把job持久化到数据库中',IS_NONCONCURRENT varchar(1) not null comment '是否同时发生',IS_UPDATE_DATA varchar(1) not null comment '是否更新数据',REQUESTS_RECOVERY varchar(1) not null comment '应答恢复',JOB_DATA longblob comment 'jobDetails添加的额外信息',primary key (SCHED_NAME, JOB_NAME, JOB_GROUP)
);alter table QRTZ_JOB_DETAILS comment '定时任务 任务详情';/*==============================================================*/
/* Index: idx_qrtz_j_req_recovery */
/*==============================================================*/
create index idx_qrtz_j_req_recovery on QRTZ_JOB_DETAILS
(SCHED_NAME,REQUESTS_RECOVERY
);/*==============================================================*/
/* Index: idx_qrtz_j_grp */
/*==============================================================*/
create index idx_qrtz_j_grp on QRTZ_JOB_DETAILS
(SCHED_NAME,JOB_GROUP
);
2.8、QRTZ_LOCKS
Quartz提供的锁表的信息(悲观锁),为多个节点调度提供分布式锁,实现分布式调度,默认有2个锁
drop table if exists QRTZ_LOCKS;/*==============================================================*/
/* Table: QRTZ_LOCKS */
/*==============================================================*/
create table QRTZ_LOCKS
(SCHED_NAME varchar(120) not null comment '调度器名称',LOCK_NAME varchar(40) not null comment '锁名称',primary key (SCHED_NAME, LOCK_NAME)
);alter table QRTZ_LOCKS comment '定时任务 悲观锁';
2.9、QRTZ_CALENDARS
drop table if exists QRTZ_CALENDARS;/*==============================================================*/
/* Table: QRTZ_CALENDARS */
/*==============================================================*/
create table QRTZ_CALENDARS
(SCHED_NAME varchar(120) not null comment '调度器名称',CALENDAR_NAME varchar(200) not null comment '日历名称',CALENDAR longblob not null comment '日历',primary key (SCHED_NAME, CALENDAR_NAME)
);alter table QRTZ_CALENDARS comment '定时任务 日历';
就先到这里吧,下一章将继续讲解springboot整合quartz
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
