一个简单的job工程

QuartzScheduled

package com.jht.jsicp.job.engine.annotation;

/**
 * 此类跟Spring的@Scheduled 注解一样,只是此注解后,使用的是quartz来调度定时任务
 */
public @interface QuartzScheduled {

}

AutoWiredSpringBeanToJobFactory

package com.jht.jsicp.job.engine.config;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;

public class AutoWiredSpringBeanToJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
    private transient AutowireCapableBeanFactory beanFactory;

    @Override
    public void setApplicationContext(final ApplicationContext context) {
        beanFactory = context.getAutowireCapableBeanFactory();
    }

    @Override
    protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
        final Object job = super.createJobInstance(bundle);
        beanFactory.autowireBean(job);
        return job;
    }

}

QuartzClusterConfigure

package com.jht.jsicp.job.engine.config;

import org.quartz.CronTrigger;
import org.quartz.Trigger;
import org.quartz.spi.JobFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

@Configuration
@EnableScheduling
public class QuartzClusterConfigure implements ApplicationContextAware {

    private static final String QUARTZ_CONFIG = "/config/quartz.properties";

    private ApplicationContext applicationContext;

    @Autowired
    @Qualifier(value = "dataSource")
    private DataSource dataSource;

    /**
     * 从quartz.properties文件中读取Quartz配置属性
     *
     * @return properties
     * @throws IOException 异常信息
     */
    @Bean
    public Properties quartzProperties() throws IOException {
        PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource(QUARTZ_CONFIG));
        propertiesFactoryBean.afterPropertiesSet();
        return propertiesFactoryBean.getObject();
    }

    /**
     * JobFactory与schedulerFactoryBean中的JobFactory相互依赖,注意bean的名称
     * 在这里为JobFactory注入了Spring上下文
     *
     * @param applicationContext spring上下文
     * @return jobFactory
     */
    @Bean
    public JobFactory jobFactory(ApplicationContext applicationContext) {
        AutoWiredSpringBeanToJobFactory jobFactory = new AutoWiredSpringBeanToJobFactory();
        jobFactory.setApplicationContext(applicationContext);
        return jobFactory;
    }

    /**
     * @param jobFactory 为SchedulerFactory配置JobFactory
     * @return SchedulerFactoryBean
     * @throws IOException 异常
     */
    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory) throws IOException {
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        factory.setJobFactory(jobFactory);
        factory.setOverwriteExistingJobs(true);
        // 设置调度器自动运行
        factory.setAutoStartup(true);
        factory.setQuartzProperties(quartzProperties());
        // 使用应用的dataSource替换quartz的dataSource
        factory.setDataSource(dataSource);
        //当spring关闭时,会等待所有已经启动的quartz job 结束后spring才能完全shutdown
        factory.setWaitForJobsToCompleteOnShutdown(true);
        factory.setStartupDelay(1);
        //添加所有的trigger
        List triggers = new ArrayList<>();
        if (this.applicationContext != null) {
            //不需要重复注册
//            Map cronTriggerFactoryBeanMap = this.applicationContext.getBeansOfType(CronTriggerFactoryBean.class);
//            if (cronTriggerFactoryBeanMap!=null && cronTriggerFactoryBeanMap.size()>0){
//                for(Map.Entry entry:cronTriggerFactoryBeanMap.entrySet()){
//                    CronTriggerFactoryBean cronTriggerFactoryBean = entry.getValue();
//                    CronTrigger cronTrigger = cronTriggerFactoryBean.getObject();
//                    if(!triggers.contains(cronTrigger)){
//                        triggers.add(cronTrigger);
//                    }
//                }
//            }
            Map cronTriggerMap = this.applicationContext.getBeansOfType(CronTrigger.class);
            if (cronTriggerMap != null && cronTriggerMap.size() > 0) {
                for (Map.Entry entry : cronTriggerMap.entrySet()) {
                    CronTrigger cronTrigger = entry.getValue();
                    if (!triggers.contains(cronTrigger)) {
                        triggers.add(cronTrigger);
                    }
                }
            }
        }
        factory.setTriggers(triggers.toArray(new Trigger[0]));
        factory.setApplicationContextSchedulerContextKey("applicationContext");
        return factory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

QuartzController

package com.jht.jsicp.job.engine.controller;

import com.jht.jsicp.job.engine.entry.JobResponse;
import com.jht.jsicp.job.engine.service.QuartzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/quartz")
public class QuartzController {

    @Autowired
    private QuartzService quartzService;

    @GetMapping(value = "/pause", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JobResponse pauseJob(String jobName, String groupName) {
        quartzService.pauseJob(jobName, groupName);
        return JobResponse.success();
    }


    @GetMapping(value = "/resume", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JobResponse resumeJob(String jobName, String groupName) {
        quartzService.resumeJob(jobName, groupName);
        return JobResponse.success();
    }

    @GetMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JobResponse deleteJob(String jobName, String groupName) {
        quartzService.deleteJob(jobName, groupName);
        return JobResponse.success();
    }


    @GetMapping(value = "/run", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JobResponse run(String jobName, String groupName) {
        quartzService.doJob(jobName, groupName);
        return JobResponse.success();
    }

    @PostMapping(value = "/startAll", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JobResponse startAllJob() {
        quartzService.startAllJob();
        return JobResponse.success();
    }

    @PostMapping(value = "shutdown", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public JobResponse shutdown() {
        quartzService.shutdown();
        return JobResponse.success();
    }
}

JobPage

package com.jht.jsicp.job.engine.entry;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;

public class JobPage {
    /**
     * 当前页
     */
    private int pageIndex;
    /**
     * 每页大小
     */
    private int pageSize;
    /**
     * 开始行
     */
    private int startRow;
    /**
     * 结束行
     */
    private int endRow;
    /**
     * 总记录数
     */
    private int total;
    /**
     * 总页数
     */
    private int pages;
    /**
     * 数据
     */
    private List data;
    /**
     * 排序列
     */
    private String[] sidx;
    /**
     * 排序方向
     */
    private String[] order;


    public JobPage(int pageIndex, int pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.startRow = pageIndex > 0 ? (pageIndex - 1) * pageSize : 0;
        this.endRow = pageIndex * pageSize;
    }

    public JobPage(List result, int total, int pageSize, int pageIndex) {
        this.data = result;
        this.total = total;
        this.pageSize = pageSize;
        this.pageIndex = pageIndex;
        this.startRow = pageIndex > 0 ? (pageIndex - 1) * pageSize : 0;
        this.endRow = pageIndex * pageSize;
        this.pages = total / pageSize + (total % pageSize == 0 ? 0 : 1);
    }

    public List getData() {
        return this.data;
    }

    public void setData(List data) {
        this.data = data;
    }

    public int getPages() {
        return this.pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getEndRow() {
        return this.endRow;
    }

    public void setEndRow(int endRow) {
        this.endRow = endRow;
    }

    public int getPageNum() {
        return this.pageIndex;
    }

    public void setPageNum(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartRow() {
        return this.startRow;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    public long getTotal() {
        return this.total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    @JsonIgnore
    public int getPrev() {
        return this.pageIndex == 1 ? this.pageIndex : this.pageIndex - 1;
    }

    @JsonIgnore
    public int getNext() {
        return this.pageIndex == this.pages ? this.pageIndex : this.pageIndex + 1;
    }

}

JobResponse

package com.jht.jsicp.job.engine.entry;

public class JobResponse {
    private String code;
    private String message;
    private T data;
    private JobPage page;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public JobPage getPage() {
        return page;
    }

    public void setPage(JobPage page) {
        this.page = page;
    }

    public static  JobResponse of(JobPage page) {
        JobResponse jobResponse = new JobResponse<>();
        jobResponse.setCode("0");
        jobResponse.setPage(page);
        return jobResponse;
    }

    public static  JobResponse of(T data) {
        JobResponse jobResponse = new JobResponse<>();
        jobResponse.setCode("0");
        jobResponse.setData(data);
        return jobResponse;
    }

    public static JobResponse success() {
        JobResponse jobResponse = new JobResponse();
        jobResponse.setCode("0");
        return jobResponse;
    }

    public static JobResponse fail() {
        JobResponse jobResponse = new JobResponse();
        jobResponse.setCode("-1");
        return jobResponse;
    }
}


JobException

package com.jht.jsicp.job.engine.exception;

import java.io.Serializable;

public class JobException extends RuntimeException implements Serializable {
    private static final long serialVersionUID = 1L;
    private String code;
    private String message;
    private Throwable cause;

    public JobException() {
        super();
    }

    public JobException(String message) {
        super(message);
        this.message = message;
    }

    public JobException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public JobException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
        this.cause = cause;
    }

    public JobException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
        this.cause = cause;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public Throwable getCause() {
        return cause;
    }

    public void setCause(Throwable cause) {
        this.cause = cause;
    }
}

QuartzService

package com.jht.jsicp.job.engine.service;

public interface QuartzService {

    /**
     * 暂停一个任务
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    void pauseJob(String jobName, String jobGroupName);

    /**
     * 重启一个定时器任务
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    void resumeJob(String jobName, String jobGroupName);


    /**
     * 删除一个定时器任务,删除了,重启就没什么用了
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    void deleteJob(String jobName, String jobGroupName);


    /**
     * 根据出发规则匹配任务,立即执行定时任务,暂停的时候可以用
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    void doJob(String jobName, String jobGroupName);


    /***
     * 开启定时器,这时才可以开始所有的任务,默认是开启的
     */
    void startAllJob();


    /**
     * 关闭定时器,则所有任务不能执行和创建
     */
    void shutdown();

}

QuartzServiceImpl

package com.jht.jsicp.job.engine.service.impl;

import com.jht.jsicp.job.engine.exception.JobException;
import com.jht.jsicp.job.engine.service.QuartzService;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Quartz定时任务处理类
 */
@Service
public class QuartzServiceImpl implements QuartzService {

    private static final Logger logger = LoggerFactory.getLogger(QuartzService.class);

    @Autowired
    private Scheduler scheduler;

    /****
     * 暂停一个任务
     * @param jobName 任务名称
     * @param jobGroupName 任务组名称
     */
    @Override
    public void pauseJob(String jobName, String jobGroupName) {
        try {
            JobKey jobKey = new JobKey(jobName, jobGroupName);
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            if (jobDetail == null) {
                logger.info("未找到定时任务:{},无法暂停", jobName);
                return;
            }
            logger.info("开始暂停定时任务:{}", jobName);
            scheduler.pauseJob(jobKey);
        } catch (SchedulerException e) {
            logger.error("执行暂停定时任务:{},失败", jobName, e);
            throw new JobException("执行暂停定时任务:" + jobName + ",失败", e);
        }
    }

    /**
     * 重启一个定时器任务
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    @Override
    public void resumeJob(String jobName, String jobGroupName) {
        try {
            JobKey jobKey = new JobKey(jobName, jobGroupName);
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            if (jobDetail == null) {
                logger.info("未找到定时任务:{},无法重启", jobName);
                return;
            }
            logger.info("开始重启定时任务:{}", jobName);
            scheduler.resumeJob(jobKey);
        } catch (SchedulerException e) {
            logger.error("执行重启定时任务:{},失败", jobName, e);
            throw new JobException("执行重启定时任务:" + jobName + ",失败", e);
        }
    }


    /**
     * 删除一个定时器任务,删除了,重启就没什么用了
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    @Override
    public void deleteJob(String jobName, String jobGroupName) {
        try {
            JobKey jobKey = new JobKey(jobName, jobName);
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            if (jobDetail == null) {
                logger.info("未找到定时任务:{},无法删除", jobName);
                return;
            }
            logger.info("删除定时任务:{}", jobName);
            scheduler.deleteJob(jobKey);
        } catch (SchedulerException e) {
            logger.error("执行删除定时任务:{},失败", jobName, e);
            throw new JobException("执行删除定时任务:" + jobName + ",失败", e);
        }
    }


    /**
     * 根据出发规则匹配任务,立即执行定时任务,暂停的时候可以用
     *
     * @param jobName      任务名称
     * @param jobGroupName 任务组名称
     */
    @Override
    public void doJob(String jobName, String jobGroupName) {
        try {
            JobKey jobKey = JobKey.jobKey(jobName, jobGroupName);
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            if (jobDetail == null) {
                logger.info("未找到定时任务:{},无法执行", jobName);
                return;
            }
            logger.info("立即执行定时任务:{}", jobName);
            scheduler.triggerJob(jobKey);
        } catch (SchedulerException e) {
            logger.error("执行定时任务:{},失败", jobName, e);
            throw new JobException("执行定时任务:" + jobName + ",失败", e);
        }
    }


    /***
     * 开启定时器,这时才可以开始所有的任务,默认是开启的
     */
    @Override
    public void startAllJob() {
        try {
            scheduler.start();
        } catch (SchedulerException e) {
            throw new JobException("开启定时器失败", e);
        }
    }

    /**
     * 关闭定时器,则所有任务不能执行和创建
     */
    @Override
    public void shutdown() {
        try {
            scheduler.shutdown();
        } catch (SchedulerException e) {
            throw new JobException("关闭定时器失败", e);
        }
    }
}

Test

package com.jht.jsicp.job.engine.test;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@EnableScheduling
public class HelloWorld {

//    @Scheduled(cron = "0 0 0 0/1 * ? ")
    public void firstJob() {
        Date date = new Date();
        System.out.println("Hello World-----执行时间" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
    }

}

QuartzConfig

package com.jht.jsicp.job.engine.test.quartz;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;

//@Configuration
public class QuartzConfig {
    /**
     * 创建Job对象的方法。
     * @return
     */
    @Bean
    public JobDetailFactoryBean job() {
        JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
        jobDetailFactoryBean.setJobClass(JobTest.class);
        // 是否持久化job内容
        jobDetailFactoryBean.setDurability(true);
        // 设置是否多次请求尝试任务。
        jobDetailFactoryBean.setRequestsRecovery(true);
        return jobDetailFactoryBean;
    }

    /**
     * 创建trigger factory bean对象。
     * @return
     */
    @Bean
    public CronTriggerFactoryBean trigger() {
        CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
        cronTriggerFactoryBean.setJobDetail(job().getObject());
        cronTriggerFactoryBean.setCronExpression("0/2 * * * * ?");
        return cronTriggerFactoryBean;
    }

}

JobTest

package com.jht.jsicp.job.engine.test.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class JobTest implements Job {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        Date date = new Date();
        System.out.println("JobTest-----执行时间" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
    }

}

job_mysql_innodb.sql

/**
  用于通过页面添加,新的定时任务
*/
DROP TABLE IF EXISTS JSICP_JOB_DETAIL;

-- 动态JOB DETAIL 内容
CREATE TABLE JSICP_JOB_DETAIL (
  ID BIGINT(13) COMMENT '主键',
  NAME  VARCHAR(120) NOT NULL COMMENT '任务名称',
  CRON   VARCHAR(200) NOT NULL COMMENT 'cron表达式',
  BEAN_NAME       VARCHAR(200) NOT NULL COMMENT '任务类名',
  METHOD_NAME      VARCHAR(200) NOT NULL COMMENT '任务方法名',
  PARAM VARCHAR(200) COMMENT '参数',
  PRIORITY SMALLINT NOT NULL COMMENT '优先级',
  RUN_STATE  VARCHAR(20) NOT NULL COMMENT '运行状态',
  DATA_STATE VARCHAR(20) NOT NULL COMMENT '数据状态:DELETE;NORMAL',
  DESCRIPTION    VARCHAR(250) NULL COMMENT '任务描述',
  CREATE_TIME  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  UPDATE_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (ID)
) ENGINE=InnoDB,CHARSET=utf8;

quartz_mysql_innodb.sql

/**
本脚本为quartz 官方给的表结构
 */
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;

/**
  QRTZ_ 为所有quartz定时任务表的前缀
 */

-- 对应jobDetail
CREATE TABLE QRTZ_JOB_DETAILS (
  SCHED_NAME        VARCHAR(120) NOT NULL,
  JOB_NAME          VARCHAR(200) NOT NULL COMMENT 'job名称',
  JOB_GROUP         VARCHAR(200) NOT NULL COMMENT 'group名称',
  DESCRIPTION       VARCHAR(250) NULL COMMENT '描述',
  JOB_CLASS_NAME    VARCHAR(250) NOT NULL COMMENT 'job对应类名',
  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;

-- 对应trigger
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;
-- 简单trigger
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;
-- cron trigger
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;

-- calendar 不执行的日历
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);
commit; 

你可能感兴趣的:(一个简单的job工程)