一、quartz 表说明
序号 表名 说明
1. qrtz_calendars 以 Blob 类型存储 Quartz 的 Calendar 信息
2. qrtz_cron_triggers 存储 Cron Trigger,包括 Cron 表达式和时区信息
3. qrtz_fired_triggers 存储与已触发的 Trigger 相关的状态信息,以及相联 Job 的执行信息
4. qrtz_paused_trigger_grps 存储已暂停的 Trigger 组的信息
5. qrtz_scheduler_state 存储少量的有关调度器 (Scheduler) 的状态,和别的 调度器 (Scheduler)实例(假如是用于一个集群中)
6. qrtz_locks 存储程序的非观锁的信息(假如使用了悲观锁)
7. qrtz_job_details 存储每一个已配置的 Job 的详细信息(jobDetail)
8. qrtz_job_listeners 存储有关已配置的 Job 监听器 的信息
9. qrtz_simple_triggers 存储简单的 Trigger,包括重复次数,间隔,以及已触的次数
10. qrtz_blog_triggers 以 Blob 类型存储的Trigger
(用于 Quartz 用户用 JDBC 创建他们自己定制的 Trigger 类型,JobStore 并不知道如何存储实例的时候)
11. qrtz_trigger_listeners 存储已配置的触发器监听器 ( Trigger Listener ) 的信息
12. qrtz_triggers 存储已配置的 触发器 (Trigger) 的信息
二、quartz 的触发时间的配置
cron 方式:采用cronExpression表达式配置时间。
simple 方式:和JavaTimer差不多,可以指定一个开始时间和结束时间外加一个循环时间。
calendars 方式:可以和cron配合使用,用cron表达式指定一个触发时间规律,用calendar指定一个范围。
注意:
cron方式需要用到的4张数据表: qrtz_triggers,qrtz_cron_triggers,qrtz_fired_triggers,qrtz_job_details。
三、表创建
DROP TABLE QRTZ_FIRED_TRIGGERS; DROP TABLE QRTZ_PAUSED_TRIGGER_GRPS; DROP TABLE QRTZ_SCHEDULER_STATE; DROP TABLE QRTZ_LOCKS; DROP TABLE QRTZ_SIMPLE_TRIGGERS; DROP TABLE QRTZ_SIMPROP_TRIGGERS; DROP TABLE QRTZ_CRON_TRIGGERS; DROP TABLE QRTZ_BLOB_TRIGGERS; DROP TABLE QRTZ_TRIGGERS; DROP TABLE QRTZ_JOB_DETAILS; DROP TABLE QRTZ_CALENDARS; -- 存储每一个已配置的 Job 的详细信息 CREATE TABLE qrtz_job_details ( SCHED_NAME VARCHAR2(120) NOT NULL, JOB_NAME VARCHAR2(200) NOT NULL, JOB_GROUP VARCHAR2(200) NOT NULL, DESCRIPTION VARCHAR2(250) NULL, JOB_CLASS_NAME VARCHAR2(250) NOT NULL, IS_DURABLE VARCHAR2(1) NOT NULL, IS_NONCONCURRENT VARCHAR2(1) NOT NULL, IS_UPDATE_DATA VARCHAR2(1) NOT NULL, REQUESTS_RECOVERY VARCHAR2(1) NOT NULL, JOB_DATA BLOB NULL, CONSTRAINT QRTZ_JOB_DETAILS_PK PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) ); comment on table QRTZ_JOB_DETAILS is '存放一个jobDetail信息'; -- Add comments to the columns comment on column QRTZ_JOB_DETAILS.sched_name is '调度器名,集群环境中使用,必须使用同一个名称——集群环境下”逻辑”相同的scheduler,默认为QuartzScheduler'; comment on column QRTZ_JOB_DETAILS.job_name is '集群中job的名字'; comment on column QRTZ_JOB_DETAILS.job_group is '集群中job的所属组的名字'; comment on column QRTZ_JOB_DETAILS.job_class_name is '集群中个note job实现类的完全包名,quartz就是根据这个路径到classpath找到该job类 '; comment on column QRTZ_JOB_DETAILS.is_durable is '是否持久化,把该属性设置为1,quartz会把job持久化到数据库中'; comment on column QRTZ_JOB_DETAILS.job_data is '一个blob字段,存放持久化job对象'; -- 存储已配置的 Trigger 的信息 CREATE TABLE qrtz_triggers ( SCHED_NAME VARCHAR2(120) NOT NULL, TRIGGER_NAME VARCHAR2(200) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, JOB_NAME VARCHAR2(200) NOT NULL, JOB_GROUP VARCHAR2(200) NOT NULL, DESCRIPTION VARCHAR2(250) NULL, NEXT_FIRE_TIME NUMBER(13) NULL, PREV_FIRE_TIME NUMBER(13) NULL, PRIORITY NUMBER(13) NULL, TRIGGER_STATE VARCHAR2(16) NOT NULL, TRIGGER_TYPE VARCHAR2(8) NOT NULL, START_TIME NUMBER(13) NOT NULL, END_TIME NUMBER(13) NULL, CALENDAR_NAME VARCHAR2(200) NULL, MISFIRE_INSTR NUMBER(2) NULL, JOB_DATA BLOB NULL, CONSTRAINT QRTZ_TRIGGERS_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), CONSTRAINT QRTZ_TRIGGER_TO_JOBS_FK FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP) ); -- Add comments to the table comment on table QRTZ_TRIGGERS is '触发器的基本信息'; -- Add comments to the columns comment on column QRTZ_TRIGGERS.sched_name is '调度器名'; comment on column QRTZ_TRIGGERS.trigger_name is '触发器的名字'; comment on column QRTZ_TRIGGERS.trigger_group is '触发器所属组的名字'; comment on column QRTZ_TRIGGERS.job_name is 'qrtz_job_details表job_name的外键 '; comment on column QRTZ_TRIGGERS.job_group is 'qrtz_job_details表job_group的外键 '; comment on column QRTZ_TRIGGERS.description is '描述'; comment on column QRTZ_TRIGGERS.next_fire_time is '下一次触发时间'; comment on column QRTZ_TRIGGERS.prev_fire_time is '上一次触发时间'; comment on column QRTZ_TRIGGERS.priority is '线程优先级'; comment on column QRTZ_TRIGGERS.trigger_state is '当前trigger状态,设置为ACQUIRED,如果设置为WAITING,则job不会触发 '; comment on column QRTZ_TRIGGERS.trigger_type is '触发器类型'; comment on column QRTZ_TRIGGERS.start_time is '开始时间'; comment on column QRTZ_TRIGGERS.end_time is '结束时间'; comment on column QRTZ_TRIGGERS.calendar_name is '日历名称'; comment on column QRTZ_TRIGGERS.misfire_instr is 'Misfire处理规则,1代表【以当前时间为触发频率立刻触发一次执,然后按照Cron频率依次执行】,2代表【不触发立即执行,等待下次Cron触发频率到达时刻开始按照Cron频率依次执行】,-1代表【以错过的第一个频率时间立刻开始执行,重做错过的所有频率周期后当下一次触发频率发生时间大于当前时间后,再按照正常的Cron频率依次执行】'; comment on column QRTZ_TRIGGERS.job_data is 'JOB存储对象'; -- 存储 Cron Trigger,包括 Cron 表达式和时区信息 CREATE TABLE qrtz_cron_triggers ( SCHED_NAME VARCHAR2(120) NOT NULL, TRIGGER_NAME VARCHAR2(200) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, CRON_EXPRESSION VARCHAR2(120) NOT NULL, TIME_ZONE_ID VARCHAR2(80), CONSTRAINT QRTZ_CRON_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), CONSTRAINT QRTZ_CRON_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) ); -- Add comments to the table comment on table QRTZ_CRON_TRIGGERS is '存放cron类型的触发器'; -- Add comments to the columns comment on column QRTZ_CRON_TRIGGERS.sched_name is '集群名'; comment on column QRTZ_CRON_TRIGGERS.trigger_name is '调度器名,qrtz_triggers表trigger_name的外键 '; comment on column QRTZ_CRON_TRIGGERS.trigger_group is 'qrtz_triggers表trigger_group的外键 '; comment on column QRTZ_CRON_TRIGGERS.cron_expression is 'cron表达式 '; comment on column QRTZ_CRON_TRIGGERS.time_zone_id is '时区ID'; -- 存储少量的有关 Scheduler 的状态信息,和别的 Scheduler 实例(假如是用于一个集群中) CREATE TABLE qrtz_scheduler_state ( SCHED_NAME VARCHAR2(120) NOT NULL, INSTANCE_NAME VARCHAR2(200) NOT NULL, LAST_CHECKIN_TIME NUMBER(13) NOT NULL, CHECKIN_INTERVAL NUMBER(13) NOT NULL, CONSTRAINT QRTZ_SCHEDULER_STATE_PK PRIMARY KEY (SCHED_NAME,INSTANCE_NAME) ); -- Add comments to the table comment on table QRTZ_SCHEDULER_STATE is '调度器状态'; -- Add comments to the columns comment on column QRTZ_SCHEDULER_STATE.sched_name is '调度器名称,集群名'; comment on column QRTZ_SCHEDULER_STATE.instance_name is '集群中实例ID'; comment on column QRTZ_SCHEDULER_STATE.last_checkin_time is '上次检查时间'; comment on column QRTZ_SCHEDULER_STATE.checkin_interval is '检查时间间隔'; -- 存储与已触发的 Trigger 相关的状态信息,以及相联 Job 的执行信息 CREATE TABLE qrtz_fired_triggers ( SCHED_NAME VARCHAR2(120) NOT NULL, ENTRY_ID VARCHAR2(95) NOT NULL, TRIGGER_NAME VARCHAR2(200) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, INSTANCE_NAME VARCHAR2(200) NOT NULL, FIRED_TIME NUMBER(13) NOT NULL, SCHED_TIME NUMBER(13) NOT NULL, PRIORITY NUMBER(13) NOT NULL, STATE VARCHAR2(16) NOT NULL, JOB_NAME VARCHAR2(200) NULL, JOB_GROUP VARCHAR2(200) NULL, IS_NONCONCURRENT VARCHAR2(1) NULL, REQUESTS_RECOVERY VARCHAR2(1) NULL, CONSTRAINT QRTZ_FIRED_TRIGGER_PK PRIMARY KEY (SCHED_NAME,ENTRY_ID) ); -- 存储简单的 Trigger,包括重复次数,间隔,以及已触的次数 CREATE TABLE qrtz_simple_triggers ( SCHED_NAME VARCHAR2(120) NOT NULL, TRIGGER_NAME VARCHAR2(200) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, REPEAT_COUNT NUMBER(7) NOT NULL, REPEAT_INTERVAL NUMBER(12) NOT NULL, TIMES_TRIGGERED NUMBER(10) NOT NULL, CONSTRAINT QRTZ_SIMPLE_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), CONSTRAINT QRTZ_SIMPLE_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) ); CREATE TABLE qrtz_simprop_triggers ( SCHED_NAME VARCHAR2(120) NOT NULL, TRIGGER_NAME VARCHAR2(200) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, STR_PROP_1 VARCHAR2(512) NULL, STR_PROP_2 VARCHAR2(512) NULL, STR_PROP_3 VARCHAR2(512) NULL, INT_PROP_1 NUMBER(10) NULL, INT_PROP_2 NUMBER(10) NULL, LONG_PROP_1 NUMBER(13) NULL, LONG_PROP_2 NUMBER(13) NULL, DEC_PROP_1 NUMERIC(13,4) NULL, DEC_PROP_2 NUMERIC(13,4) NULL, BOOL_PROP_1 VARCHAR2(1) NULL, BOOL_PROP_2 VARCHAR2(1) NULL, CONSTRAINT QRTZ_SIMPROP_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), CONSTRAINT QRTZ_SIMPROP_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) ); -- Trigger 作为 Blob 类型存储(用于 Quartz 用户用 JDBC 创建他们自己定制的 Trigger 类型,<span style="color:#800080;">JobStore</span> 并不知道如何存储实例的时候) CREATE TABLE qrtz_blob_triggers ( SCHED_NAME VARCHAR2(120) NOT NULL, TRIGGER_NAME VARCHAR2(200) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, BLOB_DATA BLOB NULL, CONSTRAINT QRTZ_BLOB_TRIG_PK PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP), CONSTRAINT QRTZ_BLOB_TRIG_TO_TRIG_FK FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) ); -- 以 Blob 类型存储 Quartz 的 Calendar 信息 CREATE TABLE qrtz_calendars ( SCHED_NAME VARCHAR2(120) NOT NULL, CALENDAR_NAME VARCHAR2(200) NOT NULL, CALENDAR BLOB NOT NULL, CONSTRAINT QRTZ_CALENDARS_PK PRIMARY KEY (SCHED_NAME,CALENDAR_NAME) ); -- 存储已暂停的 Trigger 组的信息 CREATE TABLE qrtz_paused_trigger_grps ( SCHED_NAME VARCHAR2(120) NOT NULL, TRIGGER_GROUP VARCHAR2(200) NOT NULL, CONSTRAINT QRTZ_PAUSED_TRIG_GRPS_PK PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP) ); -- 存储程序的悲观锁的信息(假如使用了悲观锁) CREATE TABLE qrtz_locks ( SCHED_NAME VARCHAR2(120) NOT NULL, LOCK_NAME VARCHAR2(40) NOT NULL, CONSTRAINT QRTZ_LOCKS_PK PRIMARY KEY (SCHED_NAME,LOCK_NAME) ); create index idx_qrtz_j_req_recovery on qrtz_job_details(SCHED_NAME,REQUESTS_RECOVERY); create index idx_qrtz_j_grp on qrtz_job_details(SCHED_NAME,JOB_GROUP); create index idx_qrtz_t_j on qrtz_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP); create index idx_qrtz_t_jg on qrtz_triggers(SCHED_NAME,JOB_GROUP); create index idx_qrtz_t_c on qrtz_triggers(SCHED_NAME,CALENDAR_NAME); create index idx_qrtz_t_g on qrtz_triggers(SCHED_NAME,TRIGGER_GROUP); create index idx_qrtz_t_state on qrtz_triggers(SCHED_NAME,TRIGGER_STATE); create index idx_qrtz_t_n_state on qrtz_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE); create index idx_qrtz_t_n_g_state on qrtz_triggers(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE); create index idx_qrtz_t_next_fire_time on qrtz_triggers(SCHED_NAME,NEXT_FIRE_TIME); create index idx_qrtz_t_nft_st on qrtz_triggers(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME); create index idx_qrtz_t_nft_misfire on qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME); create index idx_qrtz_t_nft_st_misfire on qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE); create index idx_qrtz_t_nft_st_misfire_grp on qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE); create index idx_qrtz_ft_trig_inst_name on qrtz_fired_triggers(SCHED_NAME,INSTANCE_NAME); create index idx_qrtz_ft_inst_job_req_rcvry on qrtz_fired_triggers(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY); create index idx_qrtz_ft_j_g on qrtz_fired_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP); create index idx_qrtz_ft_jg on qrtz_fired_triggers(SCHED_NAME,JOB_GROUP); create index idx_qrtz_ft_t_g on qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP); create index idx_qrtz_ft_tg on qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);