springBoot-Quartz快速入门

时间:2021-07-09 16:48:13   收藏:0   阅读:21

springBoot-Quartz快速入门

开发环境

技术栈

数据库准备

说明:数据库脚本由Quartz插件包中提供
下载地址:http://www.quartz-scheduler.org/downloads/
技术分享图片

Quartz配置:spring boot 2.x 已集成Quartz,无需自己配置

spring.quartz.job-store-type=jdbc
spring.quartz.properties.org.quartz.scheduler.instanceName=clusteredScheduler
spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
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.tablePrefix=QRTZ_
spring.quartz.properties.org.quartz.jobStore.isClustered=true
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=10
spring.quartz.properties.org.quartz.threadPool.threadPriority=5
spring.quartz.properties.org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true

集群测试

spring.quartz.properties.org.quartz.jobStore.isClustered = true
spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval = 2000

本地跑两个项目,分别设置不同的端口8081和8082,启动成功以后,会发现只有一个任务在跑,然后杀掉在跑的任务,你会发现另一个项目会检测到集群中的一个任务挂了,然后接管任务。

扩展

原文:https://www.cnblogs.com/cglib/p/14990388.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!