欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

springboot整合quartz

时间:2023-06-07

因为一些需求需要一个定时任务,但Java的简单的定时任务对于多节点的情况执行会有消息不共享的问题,所以使用quartzlai实现定时任务,再此记录一下开发过程,以下是一个demo,可以直接运行。
本次开发使用的依赖是原生包,因为网络环境的原因没有使用springboot整合包。
项目结构

代码:
pom.xml
其中配置数据源的时候mysql-connector-java和spring-boot-starter-jdbc需要同时配置,不然会报数据源为空的错

<?xml version="1.0" encoding="UTF-8"?> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE com.quartzs demo 0.0.1-SNAPSHOT demo Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.quartz-scheduler quartz 2.2.1 org.springframework spring-context-support org.quartz-scheduler quartz-jobs 2.2.1 org.springframework.boot spring-boot-test 2.6.3 compile mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-jdbc com.alibaba druid 1.1.12 junit junit 4.12 compile org.springframework spring-test 5.3.15 compile org.springframework.boot spring-boot-starter-web 2.3.3.RELEASE org.springframework spring-tx 5.2.9.RELEASE com.h2database h2 runtime org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok

myQuartz.properties
配置quartz的一些参数,其中文件名不建议写quartz.properties,因为和quartz框架中默认的配置文件同名,启动的时候会将默认的配置文件覆盖,导致项目报错,报错信息为:Active Scheduler of name ‘JobScheduler’ already registered in Quartz SchedulerRepository
如果使用spring的数据源database要和spring配置相同,org.quartz.jobStore.dataSource

#可以为任意字符串,对于scheduler来说此值没有意义,但是可以区分同一系统中多个不同的实例,#如果使用了集群的功能,就必须对每一个实例使用相同的名称,这样使这些实例“逻辑上”是同一个scheduler。org.quartz.scheduler.instanceName = JobScheduler#可以是任意字符串,但如果是集群,scheduler实例的值必须唯一,可以使用AUTO自动生成。org.quartz.scheduler.instanceId = AUTOorg.quartz.scheduler.rmi.export = falseorg.quartz.scheduler.rmi.proxy = false# 默认false,若是在执行Job之前Quartz开启UserTransaction,此属性应该为true。#Job执行完毕,JobDataMap更新完(如果是StatefulJob)事务就会提交。默认值是false,可以在job类上使用@ExecuteInJTATransaction 注解,以便在各自的job上决定是否开启JTA事务。org.quartz.scheduler.wrapJobExecutionInUserTransaction = false#一个scheduler节点允许接收的trigger的最大数,默认是1,这个值越大,定时任务执行的越多,但代价是集群节点之间的不均衡。org.quartz.scheduler.batchTriggerAcquisitionMaxCount=1#线程池的实例类,(一般使用SimpleThreadPool即可满足几乎所有用户的需求)org.quartz.threadPool.class= org.quartz.simpl.SimpleThreadPool#线程数量,不会动态增加org.quartz.threadPool.threadCount= 10#线程优先级org.quartz.threadPool.threadPriority= 5#加载任务代码的ClassLoader是否从外部继承org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread= true#是否设置调度器线程为守护线程org.quartz.scheduler.makeSchedulerThreadDaemon: true#选择JDBC的存储方式org.quartz.jobStore.class= org.quartz.impl.jdbcjobstore.JobStoreTX#存储相关信息表的前缀org.quartz.jobStore.tablePrefix = QRTZ_#JobDataMaps是否都为String类型#(若是true的话,便可不用让更复杂的对象以序列化的形式保存到BLOB列中。以防序列化可能导致的版本号问题)org.quartz.jobStore.useProperties = false#最大能忍受的触发超时时间,如果超时则认为“失误”org.quartz.jobStore.misfireThreshold = 60000#是否是应用在集群中,当应用在集群中时必须设置为TRUE,否则会出错。#如果有多个Quartz实例在用同一套数据库时,必须设置为true。org.quartz.jobStore.isClustered=true#只用于设置了isClustered为true的时候,设置一个频度(毫秒),用于实例报告给集群中的其他实例。#这会影响到侦测失败实例的敏捷度。org.quartz.jobStore.clusterCheckinInterval =15000#这是JobStore能处理的错过触发的Trigger的最大数量。处理太多(2打)很快就会导致数据库表被锁定够长的时间,#这样会妨碍别的(还未错过触发)trigger执行的性能。org.quartz.jobStore.maxMisfiresToHandleAtATime=20#设置这个参数为true会告诉Quartz从数据源获取连接后不要调用它的setAutoCommit(false)方法。#在少数情况下是有用的,比如有一个驱动本来是关闭的,但是又调用这个关闭的方法。但是大部分情况下驱动都要求调用setAutoCommit(false)org.quartz.jobStore.dontSetAutoCommitFalse=false#这必须是一个从LOCKS表查询一行并对这行记录加锁的SQL。假设没有设置,默认值如下。#{0}会在运行期间被前面配置的TABLE_PREFIX所代替org.quartz.jobStore.selectWithLockSQL=SELECT * FROM {0}LOCKS WHERe LOCK_NAME = ? FOR UPDATE#值为true时告知Quartz(当使用JobStoreTX或CMT)调用JDBC连接的setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE) 方法。这有助于某些数据库在高负载和长时间事务时锁的超时。org.quartz.jobStore.txIsolationLevelSerializable=falsequartz.job-store-type=jdbcorg.quartz.jobStore.dataSource = com.mysql.cj.jdbc.Driver

application.properties
配置数据库连接的时候要配置时区不然会报错,报错为:The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone、You must configure either the server or JDBC driver (via the ‘serverTimezone’ configuration property) to use a more specifc time zone value if you want to utiliz

server.port=8080spring.application.name=quartz1spring.profiles.active=quartz# 连接四大参数spring.datasource.url=jdbc:mysql://localhost:3306/quartz1?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTCspring.datasource.username=rootspring.datasource.password=rootspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

QuartzConfig.java
初始化Scheduler,注入scheduler的时候要加上@Primay注解,不然会扫描多个注入报错:Field scheduler in com.quartzs.demo.util.QuartzJobManager required a single bean, but 2 were found:
- schedulerFactoryBean: defined by method ‘schedulerFactoryBean’ in class path resource [com/quartzs/demo/config/QuartzConfig.class]
- Scheduler: defined by method ‘scheduler’ in class path resource [com/quartzs/demo/config/QuartzConfig.class]

package com.quartzs.demo.config;import org.quartz.Scheduler;import org.quartz.ee.servlet.QuartzInitializerListener;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.config.PropertiesFactoryBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Primary;import org.springframework.core.io.ClassPathResource;import org.springframework.scheduling.annotation.EnableScheduling;import org.springframework.scheduling.quartz.SchedulerFactoryBean;import javax.sql.DataSource;import java.io.IOException;import java.util.Properties;@Configuration@EnableSchedulingpublic class QuartzConfig { @Autowired private DataSource dataSource; @Bean public SchedulerFactoryBean schedulerFactoryBean() throws IOException { SchedulerFactoryBean factory = new SchedulerFactoryBean(); factory.setQuartzProperties(quartzProperties()); factory.setDataSource(dataSource); return factory; } @Bean public Properties quartzProperties() throws IOException { PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(); propertiesFactoryBean.setLocation(new ClassPathResource("/myQuartz.properties")); //在quartz.properties中的属性被读取并注入后再初始化对象 propertiesFactoryBean.afterPropertiesSet(); return propertiesFactoryBean.getObject(); } @Bean public QuartzInitializerListener executorListener() { return new QuartzInitializerListener(); } @Primary @Bean(name = "Scheduler") public Scheduler scheduler() throws IOException { return schedulerFactoryBean().getScheduler(); }}

TaskJobFactory.java
2.x版本一下无法注入job,此类解决quartz无法注入bean的问题

package com.quartzs.demo.config;import org.quartz.spi.TriggerFiredBundle;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.config.AutowireCapableBeanFactory;import org.springframework.scheduling.quartz.AdaptableJobFactory;public class TaskJobFactory extends AdaptableJobFactory { @Autowired private AutowireCapableBeanFactory capableBeanFactory; @Override protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { //调用父类方法 Object jobInstance = super.createJobInstance(bundle); //进行注入 capableBeanFactory.autowireBean(jobInstance); return jobInstance; }}

HelloJob.java
定时任务的逻辑代码类,业务逻辑都是写在这个里面,需要实现job类
如果需要传参数可以放在JobDataMap里,这是一个string,object的map集合,可以根据jobExecutionContext.getJobDetail().getJobDataMap().get(key);取到参数值,可以放多个

package com.quartzs.demo.service;import org.quartz.Job;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;public class HelloJob implements Job { @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { // 业务逻辑 System.out.println("定时任务开始执行"); Object id = jobExecutionContext.getJobDetail().getJobDataMap().get("id"); System.out.println("定时任务的id为{}"+id); }}

QuartzJobManager.java
主要是封装定时任务的启动修改删除的一些工具,其中定时任务修改可以多加一个Class类型传入要执行定时任务的逻辑类,根据class类型可以执行不同的方法,因为涉及我的业务只有一个方法所以没有加

package com.quartzs.demo.util;import com.quartzs.demo.service.HelloJob;import lombok.extern.log4j.Log4j2;import org.quartz.*;import org.quartz.impl.matchers.GroupMatcher;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import java.util.*;@Component@Log4j2public class QuartzJobManager { private static QuartzJobManager jobUtil; @Autowired private Scheduler scheduler; public QuartzJobManager() { log.info("QuartzJobManager init"); jobUtil = this; } public static QuartzJobManager getInstance() { log.info("return JobUtil"); return QuartzJobManager.jobUtil; } public void addJob(String jobName, String jobGroupName, String cronexpression) throws Exception { //启动调度器 scheduler.start(); //构建job信息 HelloJob:执行定时任务的具体代码 JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity(jobName, jobGroupName).build(); //表达式调度构造起,任务执行时间 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronexpression); //根据任务执行时间的cron表达式构建trigger触发器 CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobName, jobGroupName).withSchedule(scheduleBuilder).build(); scheduler.scheduleJob(jobDetail, trigger); } public void addJob(String jobName, String jobGroupName, String cronexpression, Map argMap) throws Exception { // 启动调度器 scheduler.start(); //构建job信息 JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity(jobName, jobGroupName).build(); //传入参数 jobDetail.getJobDataMap().putAll(argMap); //表达式调度构建器(即任务执行的时间) CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronexpression); //按新的cronexpression表达式构建一个新的trigger CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobName, jobGroupName) .withSchedule(scheduleBuilder).build(); //获得JobDataMap,写入数据 //trigger.getJobDataMap().putAll(argMap); scheduler.scheduleJob(jobDetail, trigger); } public void pauseJob(String jobName, String jobGroupName) throws SchedulerException { scheduler.pauseJob(JobKey.jobKey(jobName, jobGroupName)); } public void resumeJob(String jobName, String jobGroupName) throws SchedulerException { scheduler.resumeJob(JobKey.jobKey(jobName, jobGroupName)); } public void updateJob(String jobName, String jobGroupName, String cronexpression) throws Exception { TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroupName); // 表达式调度构建器 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronexpression); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 按新的cronexpression表达式重新构建trigger trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); // 按新的trigger重新设置job执行 scheduler.rescheduleJob(triggerKey, trigger); } public void updateJob(String jobName, String jobGroupName, String cronexpression, Map argMap) throws Exception { TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroupName); // 表达式调度构建器 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronexpression); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 按新的cronexpression表达式重新构建trigger trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); //修改map trigger.getJobDataMap().putAll(argMap); // 按新的trigger重新设置job执行 scheduler.rescheduleJob(triggerKey, trigger); } public void updateJob(String jobName, String jobGroupName, Map argMap) throws Exception { TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroupName); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); //修改map trigger.getJobDataMap().putAll(argMap); // 按新的trigger重新设置job执行 scheduler.rescheduleJob(triggerKey, trigger); } public void deleteJob(String jobName, String jobGroupName) throws Exception { scheduler.pauseTrigger(TriggerKey.triggerKey(jobName, jobGroupName)); scheduler.unscheduleJob(TriggerKey.triggerKey(jobName, jobGroupName)); scheduler.deleteJob(JobKey.jobKey(jobName, jobGroupName)); } public void startAllJobs() { try { scheduler.start(); } catch (Exception e) { throw new RuntimeException(e); } } public void shutdownAllJobs() { try { if (!scheduler.isShutdown()) { scheduler.shutdown(); } } catch (Exception e) { throw new RuntimeException(e); } } public List> getAllJob() throws SchedulerException { GroupMatcher matcher = GroupMatcher.anyJobGroup(); Set jobKeys = scheduler.getJobKeys(matcher); List> jobList = new ArrayList<>(); for (JobKey jobKey : jobKeys) { List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey); for (Trigger trigger : triggers) { Map job = new HashMap<>(); job.put("jobName", jobKey.getName()); job.put("jobGroupName", jobKey.getGroup()); job.put("trigger", trigger.getKey()); Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey()); job.put("jobStatus", triggerState.name()); if (trigger instanceof CronTrigger) { CronTrigger cronTrigger = (CronTrigger) trigger; String cronexpression = cronTrigger.getCronexpression(); job.put("cronexpression", cronexpression); } jobList.add(job); } } return jobList; }}

TestController.java
测试类,类上记得要加@RestController或者方法上加@ResponseBody注解,不然解析参数时会报错:Circular view path [addTasks]: would dispatch back to the current handler URL [/addTasks]]
代码中的map集合存放所需的业务参数

package com.quartzs.demo.controller;import com.quartzs.demo.util.DateCronUtil;import com.quartzs.demo.util.QuartzJobManager;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.Date;import java.util.HashMap;import java.util.Map;@RestControllerpublic class TestController { @Autowired private QuartzJobManager manager; @RequestMapping("/addTasks") public void addTask(String timeStr) throws Exception { Date date = DateCronUtil.dateTo(timeStr); String s = DateCronUtil.dateToCron(date); Map map = new HashMap<>(); map.put("id","23984901"); manager.addJob("23984901","quartzGroup",s,map); System.out.println("定时任务完成"); } @RequestMapping("/updTasks") public void updTask(String timeStr) throws Exception { Date date = DateCronUtil.dateTo(timeStr); String s = DateCronUtil.dateToCron(date); String id = "23984901"; Map map = new HashMap<>(); map.put("id","xnsdiwnrk"); manager.updateJob(id,"quartzGroup",s,map); System.out.println("定时任务修改完成"); }}

定时任务我需要的是指定时间执行,且只执行一次,我将时间转为cron表达式传入参数中,时间转换工具类在下面
DateCronUtil.java

package com.quartzs.demo.util;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class DateCronUtil { public static String dateToCron(Date date) { SimpleDateFormat format = new SimpleDateFormat("ss mm HH dd MM ? yyyy"); return format.format(date); } public static Date dateTo(String date) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); Date parse =null; try { parse = format.parse(date); } catch (ParseException e) { e.printStackTrace(); } return parse; }}

最后启动类上面加上事务开启的注解,deam完成
DemoApplication.java

package com.quartzs.demo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.transaction.annotation.EnableTransactionManagement;@SpringBootApplication@EnableTransactionManagementpublic class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}

最后附加quartz建表语句(mysql),需要其他数据库建表语句可以从quartz jar包的org.quartz.impl.jdbcjobstore位置下面下载

-- mysql ---DROP TABLE IF EXISTS QRTZ_FIRED_TRIGGERS;DROP TABLE IF EXISTS QRTZ_PAUSED_TRIGGER_GRPS;DROP TABLE IF EXISTS QRTZ_SCHEDULER_STATE;DROP TABLE IF EXISTS QRTZ_LOCKS;DROP TABLE IF EXISTS QRTZ_SIMPLE_TRIGGERS;DROP TABLE IF EXISTS QRTZ_SIMPROP_TRIGGERS;DROP TABLE IF EXISTS QRTZ_CRON_TRIGGERS;DROP TABLE IF EXISTS QRTZ_BLOB_TRIGGERS;DROP TABLE IF EXISTS QRTZ_TRIGGERS;DROP TABLE IF EXISTS QRTZ_JOB_DETAILS;DROP TABLE IF EXISTS QRTZ_CALENDARS;CREATE TABLE QRTZ_JOB_DETAILS(SCHED_NAME VARCHAR(120) NOT NULL,JOB_NAME VARCHAR(200) NOT NULL,JOB_GROUP VARCHAR(200) NOT NULL,DEscriptION VARCHAR(250) NULL,JOB_CLASS_NAME VARCHAR(250) NOT NULL,IS_DURABLE VARCHAR(1) NOT NULL,IS_NONCONCURRENT VARCHAR(1) NOT NULL,IS_UPDATE_DATA VARCHAR(1) NOT NULL,REQUESTS_RECOVERY VARCHAR(1) NOT NULL,JOB_DATA BLOB NULL,PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_TRIGGERS (SCHED_NAME VARCHAR(120) NOT NULL,TRIGGER_NAME VARCHAR(200) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,JOB_NAME VARCHAR(200) NOT NULL,JOB_GROUP VARCHAR(200) NOT NULL,DEscriptION VARCHAR(250) NULL,NEXT_FIRE_TIME BIGINT(13) NULL,PREV_FIRE_TIME BIGINT(13) NULL,PRIORITY INTEGER NULL,TRIGGER_STATE VARCHAR(16) NOT NULL,TRIGGER_TYPE VARCHAR(8) NOT NULL,START_TIME BIGINT(13) NOT NULL,END_TIME BIGINT(13) NULL,CALENDAR_NAME VARCHAR(200) NULL,MISFIRE_INSTR SMALLINT(2) NULL,JOB_DATA BLOB NULL,PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_SIMPLE_TRIGGERS (SCHED_NAME VARCHAR(120) NOT NULL,TRIGGER_NAME VARCHAR(200) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,REPEAT_COUNT BIGINT(7) NOT NULL,REPEAT_INTERVAL BIGINT(12) NOT NULL,TIMES_TRIGGERED BIGINT(10) NOT NULL,PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_CRON_TRIGGERS (SCHED_NAME VARCHAR(120) NOT NULL,TRIGGER_NAME VARCHAR(200) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,CRON_expression VARCHAR(120) NOT NULL,TIME_ZONE_ID VARCHAR(80),PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_SIMPROP_TRIGGERS(SCHED_NAME VARCHAR(120) NOT NULL,TRIGGER_NAME VARCHAR(200) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,STR_PROP_1 VARCHAR(512) NULL,STR_PROP_2 VARCHAR(512) NULL,STR_PROP_3 VARCHAR(512) NULL,INT_PROP_1 INT NULL,INT_PROP_2 INT NULL,LONG_PROP_1 BIGINT NULL,LONG_PROP_2 BIGINT NULL,DEC_PROP_1 NUMERIC(13,4) NULL,DEC_PROP_2 NUMERIC(13,4) NULL,BOOL_PROP_1 VARCHAR(1) NULL,BOOL_PROP_2 VARCHAR(1) NULL,PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_BLOB_TRIGGERS (SCHED_NAME VARCHAR(120) NOT NULL,TRIGGER_NAME VARCHAR(200) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,BLOB_DATA BLOB NULL,PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),INDEX (SCHED_NAME,TRIGGER_NAME, TRIGGER_GROUP),FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_CALENDARS (SCHED_NAME VARCHAR(120) NOT NULL,CALENDAR_NAME VARCHAR(200) NOT NULL,CALENDAR BLOB NOT NULL,PRIMARY KEY (SCHED_NAME,CALENDAR_NAME))ENGINE=InnoDB;CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS (SCHED_NAME VARCHAR(120) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP))ENGINE=InnoDB;CREATE TABLE QRTZ_FIRED_TRIGGERS (SCHED_NAME VARCHAR(120) NOT NULL,ENTRY_ID VARCHAR(95) NOT NULL,TRIGGER_NAME VARCHAR(200) NOT NULL,TRIGGER_GROUP VARCHAR(200) NOT NULL,INSTANCE_NAME VARCHAR(200) NOT NULL,FIRED_TIME BIGINT(13) NOT NULL,SCHED_TIME BIGINT(13) NOT NULL,PRIORITY INTEGER NOT NULL,STATE VARCHAR(16) NOT NULL,JOB_NAME VARCHAR(200) NULL,JOB_GROUP VARCHAR(200) NULL,IS_NONCONCURRENT VARCHAR(1) NULL,REQUESTS_RECOVERY VARCHAR(1) NULL,PRIMARY KEY (SCHED_NAME,ENTRY_ID))ENGINE=InnoDB;CREATE TABLE QRTZ_SCHEDULER_STATE (SCHED_NAME VARCHAR(120) NOT NULL,INSTANCE_NAME VARCHAR(200) NOT NULL,LAST_CHECKIN_TIME BIGINT(13) NOT NULL,CHECKIN_INTERVAL BIGINT(13) NOT NULL,PRIMARY KEY (SCHED_NAME,INSTANCE_NAME))ENGINE=InnoDB;CREATE TABLE QRTZ_LOCKS (SCHED_NAME VARCHAR(120) NOT NULL,LOCK_NAME VARCHAR(40) NOT NULL,PRIMARY KEY (SCHED_NAME,LOCK_NAME))ENGINE=InnoDB;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);

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。