• Quartz持久化和RAM两种使用方式,Job实现注入service,execute方法传入执行参数


    A、项目中引入相关依赖

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-quartz</artifactId>
    </dependency>
    

      

     

    我使用的項目是Springboot,因此这里我可以使用插件,如果你使用的单独的项目你可以这么配置:

    <!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.3.0</version>
    </dependency>
    

      

    查询依赖的maven仓库地址为:http://mvnrepository.com/

    B、进行相关配置操作

    配置文件 :quartz.properties

    # 固定前缀org.quartz
    # 主要分为scheduler、threadPool、jobStore、plugin等部分
    #
    #
    org.quartz.scheduler.instanceName=DefaultQuartzScheduler
    org.quartz.scheduler.rmi.export=false
    org.quartz.scheduler.rmi.proxy=false
    org.quartz.scheduler.wrapJobExecutionInUserTransaction=false
    
    # 实例化ThreadPool时,使用的线程类为SimpleThreadPool
    org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
    
    # threadCount和threadPriority将以setter的形式注入ThreadPool实例
    # 并发个数
    org.quartz.threadPool.threadCount=5
    # 优先级
    org.quartz.threadPool.threadPriority=5
    org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
    
    org.quartz.jobStore.misfireThreshold=5000
    
    # 默认存储在内存中(不需要配置 可以在源码中的properties中看到这个配置)
    #org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
    
    # ——————————————————————————————上面展示的是非持久的配置————————————————————————————————————————————————————
    

      

    使用配置:

    package com.meimei.quartz_demo.config;
    
    import org.quartz.Scheduler;
    import org.quartz.ee.servlet.QuartzInitializerListener;
    import org.springframework.beans.factory.config.PropertiesFactoryBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.scheduling.quartz.SchedulerFactoryBean;
    
    import java.io.IOException;
    import java.util.Properties;
    
    /**
     * @author licunzhi
     * @desc quartz configuration(we can also use xml, but springboot recommend to use annotation @configuration to config)
     * @date 2018-09-05
     */
    @Configuration
    public class QuartzConfiguration {
    
        @Bean(name="SchedulerFactory")
        public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
            SchedulerFactoryBean factory = new SchedulerFactoryBean();
            PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
            propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
            //在quartz.properties中的属性被读取并注入后再初始化对象
            propertiesFactoryBean.afterPropertiesSet();
            Properties properties = propertiesFactoryBean.getObject();
            factory.setQuartzProperties(properties);
            return factory;
        }
    
        /*
         * quartz初始化监听器
         */
        @Bean
        public QuartzInitializerListener executorListener() {
            return new QuartzInitializerListener();
        }
    
        /*
         * 通过SchedulerFactoryBean获取Scheduler的实例
         */
        @Bean(name="Scheduler")
        public Scheduler scheduler() throws IOException {
            return schedulerFactoryBean().getScheduler();
        }
    
    }
    

      

    编写简单的JOB类准备使用

    package com.meimei.quartz_demo.job;
    
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    
    public class SampleJob implements Job {
    
        public SampleJob() {
        }
    
        public void execute(JobExecutionContext context) {
            System.out.println("执行方法。。。。。" + id);
        }
    }
    

      

    启动类配置(注意使用注解@EnableScheduling)

    package com.meimei.quartz_demo;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
    import org.springframework.scheduling.annotation.EnableScheduling;
    
    @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    @EnableScheduling//开启定时任务功能
    public class QuartzDemoApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(QuartzDemoApplication.class, args);
        }
    }
    

      

    C、如何使用

    package com.meimei.quartz_demo.api;
    
    import com.meimei.quartz_demo.job.SampleJob;
    import org.apache.juli.logging.Log;
    import org.apache.juli.logging.LogFactory;
    import org.quartz.CronScheduleBuilder;
    import org.quartz.CronTrigger;
    import org.quartz.JobBuilder;
    import org.quartz.JobDetail;
    import org.quartz.JobKey;
    import org.quartz.Scheduler;
    import org.quartz.SchedulerException;
    import org.quartz.TriggerBuilder;
    import org.quartz.TriggerKey;
    import org.quartz.impl.matchers.GroupMatcher;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.util.Set;
    
    /**
     * @author licunzhi
     * @desc 方便调用这里全部操作为get操作
     * @date 2018-09-07
     */
    @RestController
    @RequestMapping("/job")
    public class JobController {
    
        private static final Log LOGGER = LogFactory.getLog(JobController.class);
    
        @Autowired
        @Qualifier(value = "Scheduler")
        private Scheduler scheduler;
    
        //创建一个新的job任务
        @GetMapping("/add/{jobName}")
        public void addJob(@PathVariable(value = "jobName") String jobName) {
            String groupName = "group_one"; //定义job所在组名称
            String cronExpression = "0 * * ? * * *";//执行时间表达式
            try {
                //启动任务调度器,准备添加任务相关信息操作
                scheduler.start();
    
                //构建一个新的任务规范,执行特定任务,任务执行的时间
                JobDetail jobDetail = JobBuilder
                                .newJob(SampleJob.class).withIdentity(jobName, groupName).build();
                //创建corn表达式,创建执行任务的时间规范
                CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
    
                //创建一个触发器,加入上面创建的时间规范
                CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobName, groupName)
                                .withSchedule(scheduleBuilder).build();
    
                //把执行的job任务和创建时间trigger绑定一起
                scheduler.scheduleJob(jobDetail, trigger);
    
            } catch (SchedulerException e) {
                LOGGER.info("scheduler start or shutdown error ...");
            }
    
        }
    
        //查询所有的任务
        @GetMapping("/search")
        public String searchJob() throws SchedulerException {
            String groupName = "group_one"; //定义job所在组名称
            Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
            StringBuilder message = new StringBuilder();
            for (JobKey jobKey : jobKeys) {
                message.append(jobKey.getName() + "----------------" + jobKey.getGroup() + "
    ");
            }
            return message.toString();
        }
    
        @GetMapping("/pause/{jobName}")
        public String pauseJob(@PathVariable(value = "jobName") String jobName) throws SchedulerException {
            String groupName = "group_one"; //定义job所在组名称
            scheduler.pauseJob(JobKey.jobKey(jobName, groupName));
            return "success";
        }
    
        @GetMapping("/recover/{jobName}")
        public String recoverJob(@PathVariable(value = "jobName") String jobName) throws SchedulerException {
            String groupName = "group_one"; //定义job所在组名称
            scheduler.resumeJob(JobKey.jobKey(jobName, groupName));
            return "success";
        }
    
        @GetMapping("/delete/{jobName}")
        public String deleteJob(@PathVariable(value = "jobName") String jobName) throws SchedulerException {
            String groupName = "group_one"; //定义job所在组名称
            scheduler.deleteJob(JobKey.jobKey(jobName, groupName));
            return "success";
        }
    
        @GetMapping("/update/{jobName}")
        public String updateJob(@PathVariable(value = "jobName") String jobName) throws SchedulerException {
            String groupName = "group_one"; //定义job所在组名称
            String cronExpression = "* * * ? * * *";//执行时间表达式
            try {
                TriggerKey triggerKey = TriggerKey.triggerKey(jobName, groupName);
    
                //创建corn表达式,创建执行任务的时间规范
                CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
    
                //获取trigger
                CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
    
                //把执行的job任务和创建时间trigger绑定一起
                trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
    
                scheduler.rescheduleJob(triggerKey, trigger);
            } catch (SchedulerException e) {
                LOGGER.info("scheduler start or shutdown error ...");
            }
    
            return "success";
    
        }
    }
    

      

    备注:上面的方法中更没有在job方法中的默认执行操作传入参数,如果你需要传入指定的参数可以使用下面的代码

    //创建一个新的job任务
        @GetMapping("/add/{jobName}")
        public void addJob(@PathVariable(value = "jobName") String jobName) {
            String groupName = "group_one"; //定义job所在组名称
            String cronExpression = "0 * * ? * * *";//执行时间表达式
            try {
                //启动任务调度器,准备添加任务相关信息操作
                scheduler.start();
    
                //构建一个新的任务规范,执行特定任务,任务执行的时间
                JobDetail jobDetail = JobBuilder
                                .newJob(SampleJob.class).withIdentity(jobName, groupName).build();
                //执行的任务中传入参数------------------------------
                jobDetail.getJobDataMap().put("sakura", "sakura");
                //------------------------------------------------
                //创建corn表达式,创建执行任务的时间规范
                CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
    
                //创建一个触发器,加入上面创建的时间规范
                CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobName, groupName)
                                .withSchedule(scheduleBuilder).build();
    
                //把执行的job任务和创建时间trigger绑定一起
                scheduler.scheduleJob(jobDetail, trigger);
    
            } catch (SchedulerException e) {
                LOGGER.info("scheduler start or shutdown error ...");
            }
    
        }
    

      

    在job获取设置的参数

    package com.meimei.quartz_demo.job;
    
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    
    public class SampleJob implements Job {
    
        public SampleJob() {
        }
    
        public void execute(JobExecutionContext context) {
            String id = context.getJobDetail().getJobDataMap().get("sakura").toString();
            System.out.println("执行方法。。。。。" + id);
        }
    }
    

      

    D、如果想在job中注入指定的service,从而实现执行指定的service方法如何做

    a 自定义个factory

    package com.meimei.quartz_demo.factory;
    
    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;
    import org.springframework.stereotype.Component;
    
    /**
     * @author licunzhi
     * @desc 自定义工厂类
     * @date 2018-09-09
     */
    @Component
    public class SchedulerFactory extends AdaptableJobFactory {
    
        //spring bean 对象管理工厂
        @Autowired
        private AutowireCapableBeanFactory capableBeanFactory;
    
        protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
            //调用父类的方法
            Object jobInstance = super.createJobInstance(bundle);
            //自动注入
            capableBeanFactory.autowireBean(jobInstance);
            return jobInstance;
        }
    }
    

      

    b 设置自定义工厂类为quartz的factorybean(有关自定义的factorybean后面会单独较为浅的源码层分析一篇博客)

    package com.meimei.quartz_demo.config;
    
    import com.meimei.quartz_demo.factory.SchedulerFactory;
    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.core.io.ClassPathResource;
    import org.springframework.scheduling.quartz.SchedulerFactoryBean;
    
    import java.io.IOException;
    import java.util.Properties;
    
    /**
     * @author licunzhi
     * @desc quartz configuration(we can also use xml, but springboot recommend to use annotation @configuration to config)
     * @date 2018-09-05
     */
    @Configuration
    public class QuartzConfiguration {
    
        // 注入service需要配置工厂类
        @Autowired
        private SchedulerFactory schedulerFactory;
    
        @Bean(name="SchedulerFactory")
        public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
            SchedulerFactoryBean factory = new SchedulerFactoryBean();
            // 注入service需要配置工厂类
            factory.setJobFactory(schedulerFactory);
            // 注入service需要配置工厂类
    
            PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
            propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
            //在quartz.properties中的属性被读取并注入后再初始化对象
            propertiesFactoryBean.afterPropertiesSet();
            Properties properties = propertiesFactoryBean.getObject();
            factory.setQuartzProperties(properties);
            return factory;
        }
    
        /*
         * quartz初始化监听器
         */
        @Bean
        public QuartzInitializerListener executorListener() {
            return new QuartzInitializerListener();
        }
    
        /*
         * 通过SchedulerFactoryBean获取Scheduler的实例
         */
        @Bean(name="Scheduler")
        public Scheduler scheduler() throws IOException {
            return schedulerFactoryBean().getScheduler();
        }
    
    }
    

      

    c 自定义的job类作为容器初始话的组件对象

    package com.meimei.quartz_demo.job;
    
    import com.meimei.quartz_demo.service.ServiceDemo;
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;
    
    @Component
    public class JobOne implements Job {
    
        @Autowired
        private ServiceDemo serviceDemo;
    
        public void execute(JobExecutionContext context) {
            System.out.println("执行方法servicedemo中的方法");
            serviceDemo.sakura();
            System.out.println("执行方法servicedemo中的方法");
        }
    }
    

      

    E、持久化的操作怎么做

    a 增加下面的配置文件,数据库链接的信息是自己创建的数据库环境

    # —————————————————————下面是持久化的配置,使用时修改配置参数即可(运行脚本放在项目下的scripts,选择合的数据库即可)———————————————————————————————————————————
    
    #持久化(需要配置持久化的类型----jdbc和兵马俑两种)
    org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
    # 数据库表名称前缀
    org.quartz.jobStore.tablePrefix=QRTZ_
    # 持久化的数据库名称
    org.quartz.jobStore.dataSource=quartz
    # 数据库驱动类型
    org.quartz.dataSource.quartz.driver=com.mysql.jdbc.Driver
    # 数据库链接地址
    org.quartz.dataSource.quartz.URL=jdbc:mysql://localhost:3306/quartz?useUnicode=true&characterEncoding=UTF-8
    # 用户名
    org.quartz.dataSource.quartz.user=root
    # 密码
    org.quartz.dataSource.quartz.password=123
    # 最大连接数
    org.quartz.dataSource.quartz.maxConnections=10
    # 使用持久化配置
    org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
    

      

    b 执行初始化数据库脚本(这里使用的是tables_mysql_innodb.sql)

    #
    # In your Quartz properties file, you'll need to set
    # org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
    #
    #
    # By: Ron Cordell - roncordell
    #  I didn't see this anywhere, so I thought I'd post it here. This is the script from Quartz to create the tables in a MySQL database, modified to use INNODB instead of MYISAM.
    
    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(190) NOT NULL,
    JOB_GROUP VARCHAR(190) 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(190) NOT NULL,
    TRIGGER_GROUP VARCHAR(190) NOT NULL,
    JOB_NAME VARCHAR(190) NOT NULL,
    JOB_GROUP VARCHAR(190) 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(190) 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(190) NOT NULL,
    TRIGGER_GROUP VARCHAR(190) 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(190) NOT NULL,
    TRIGGER_GROUP VARCHAR(190) 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(190) NOT NULL,
        TRIGGER_GROUP VARCHAR(190) 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(190) NOT NULL,
    TRIGGER_GROUP VARCHAR(190) 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(190) 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(190) 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(190) NOT NULL,
    TRIGGER_GROUP VARCHAR(190) NOT NULL,
    INSTANCE_NAME VARCHAR(190) 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(190) NULL,
    JOB_GROUP VARCHAR(190) 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(190) 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);
    
    commit;
    

      

    sql脚本一般都在jar包文件中的doc/TBtablse文件下,如果要是找不到你可以去下载我的项目,里面有各种版本的sql

    我的项目脚本所在位置在scripts目录下

    c 操作完成之后,其余的操作和其他的一样,运行项目即可

    项目结构说明

    欢迎访问交流群:589780530 
    博主交流:2718272293
    邮箱:2718272293@qq.com  licunzhi2@gmail.com
    github: https://github.com/licunzhi

  • 相关阅读:
    【Win 10 应用开发】获取本机的IP地址
    【Win 10应用开发】延迟共享
    【Win 10 应用开发】共享目标(UWP)
    【Win 10应用开发】响应系统回退键的导航事件
    编写Windows服务疑问2:探索服务与安装器的关系
    编写Windows服务疑问1:操作过程
    服务器常见错误代码500、501、502、503、504、505
    git reset与git revert的区别
    Redis集群方案怎么做?
    ThinkPHP设计模式与Trait技术
  • 原文地址:https://www.cnblogs.com/licunzhi/p/9632838.html
Copyright © 2020-2023  润新知