Browse Source

quartz config

master
ccsens_wu 5 years ago
parent
commit
bd1da61901
  1. 128
      scheduler/src/main/java/com/ccsens/scheduler/config/SchedulerConfig.java
  2. 65
      scheduler/src/main/resources/application-dev.yml

128
scheduler/src/main/java/com/ccsens/scheduler/config/SchedulerConfig.java

@ -1,64 +1,64 @@
package com.ccsens.scheduler.config; //package com.ccsens.scheduler.config;
//
import cn.hutool.core.io.resource.ClassPathResource; //import cn.hutool.core.io.resource.ClassPathResource;
import org.quartz.Scheduler; //import org.quartz.Scheduler;
import org.quartz.ee.servlet.QuartzInitializerListener; //import org.quartz.ee.servlet.QuartzInitializerListener;
import org.springframework.beans.factory.config.PropertiesFactoryBean; //import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //import org.springframework.scheduling.quartz.SchedulerFactoryBean;
//
import java.io.IOException; //import java.io.IOException;
import java.util.Properties; //import java.util.Properties;
//
/** ///**
* @description: // * @description:
* @author: whj // * @author: whj
* @time: 2021/6/30 15:48 // * @time: 2021/6/30 15:48
*/ // */
@Configuration //@Configuration
public class SchedulerConfig { //public class SchedulerConfig {
/** // /**
* 读取quartz.properties 文件 // * 读取quartz.properties 文件
* 将值初始化 // * 将值初始化
* @return // * @return
*/ // */
@Bean // @Bean
public Properties quartzProperties() throws IOException { // public Properties quartzProperties() throws IOException {
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean(); // PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties")); // propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
propertiesFactoryBean.afterPropertiesSet(); // propertiesFactoryBean.afterPropertiesSet();
return propertiesFactoryBean.getObject(); // return propertiesFactoryBean.getObject();
} // }
//
/** // /**
* 将配置文件的数据加载到SchedulerFactoryBean中 // * 将配置文件的数据加载到SchedulerFactoryBean中
* @return // * @return
* @throws IOException // * @throws IOException
*/ // */
@Bean // @Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException { // public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); // SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setQuartzProperties(); // schedulerFactoryBean.setQuartzProperties();
return schedulerFactoryBean; // return schedulerFactoryBean;
} // }
//
/** // /**
* 初始化监听器 // * 初始化监听器
* @return // * @return
*/ // */
@Bean // @Bean
public QuartzInitializerListener executorListener(){ // public QuartzInitializerListener executorListener(){
return new QuartzInitializerListener(); // return new QuartzInitializerListener();
} // }
//
/** // /**
* 获得Scheduler 对象 // * 获得Scheduler 对象
* @return // * @return
* @throws IOException // * @throws IOException
*/ // */
@Bean // @Bean
public Scheduler scheduler() throws IOException { // public Scheduler scheduler() throws IOException {
return schedulerFactoryBean().getScheduler(); // return schedulerFactoryBean().getScheduler();
} // }
} //}

65
scheduler/src/main/resources/application-dev.yml

@ -6,38 +6,39 @@ spring:
workerId: 1 workerId: 1
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
quartz: quartz:
# dataSource: # dataSource:
# default: # default:
# driver: com.mysql.jdbc.Driver # driver: com.mysql.jdbc.Driver
# URL: jdbc:mysql://localhost:3306/jobconfig?useUnicode=true&characterEncoding=utf8 # URL: jdbc:mysql://localhost:3306/jobconfig?useUnicode=true&characterEncoding=utf8
# user: root # user: root
# password: 12345678 # password: 12345678
# maxConnections: 5 # maxConnections: 5
#相关属性配置 #相关属性配置
properties: properties:
org: org:
quartz: quartz:
scheduler: scheduler:
instanceName: quartzScheduler instanceName: quartzScheduler
instanceId: AUTO instanceId: AUTO
jobStore: jobStore:
class: org.quartz.impl.jdbcjobstore.JobStoreTX class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
tablePrefix: qrtz_ tablePrefix: QRTZ_
isClustered: false isClustered: false
clusterCheckinInterval: 10000 clusterCheckinInterval: 10000
useProperties: false useProperties: false
threadPool: threadPool:
class: org.quartz.simpl.SimpleThreadPool class: org.quartz.simpl.SimpleThreadPool
threadCount: 10 threadCount: 10
threadPriority: 5 threadPriority: 5
threadsInheritContextClassLoaderOfInitializingThread: true threadsInheritContextClassLoaderOfInitializingThread: true
#数据库方式 #数据库方式
job-store-type: JDBC job-store-type: JDBC
#初始化表结构 #初始化表结构
jdbc: jdbc:
initialize-schema: always #always never
initialize-schema: never
redis: redis:
database: 0 database: 0
host: 127.0.0.1 host: 127.0.0.1

Loading…
Cancel
Save