Quartz

分布式定时任务

配置

pom.xml添加依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
1
2
3
4

导入sql数据库表

application.properties添加

# https://medium.com/@ChamithKodikara/spring-boot-2-quartz-2-scheduler-integration-a8eaaf850805
# SpringBoot官方说明:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-quartz.html
# Quartz官方文档:https://www.quartz-scheduler.org/documentation/2.3.1-SNAPSHOT/tutorials/index.html
spring.quartz.job-store-type=jdbc
# 3种模式: ALWAYS、EMBEDDED、NEVER
spring.quartz.jdbc.initialize-schema=never
spring.quartz.properties.org.quartz.jobStore.isClustered=true
spring.quartz.properties.org.quartz.scheduler.instanceName=BytedeskScheduler
spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
#spring.quartz.properties.org.quartz.scheduler.instanceIdGenerator.class=io.xiaper.schedule.util.CustomQuartzInstanceIdGenerator
spring.quartz.properties.org.quartz.jobStore.tablePrefix=QRTZ_
spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval=10000
spring.quartz.properties.org.quartz.jobStore.useProperties=false
spring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
spring.quartz.properties.org.quartz.threadPool.threadCount=5
spring.quartz.properties.org.quartz.threadPool.threadPriority=5
spring.quartz.properties.org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

集群

spring.quartz.properties.org.quartz.jobStore.isClustered=true
1

微信公众号

参考