Quartz在spring boot项目中重启后不能继续执行问题

第一点:

CRON triggers

复制代码
  1. CronTrigger trigger = TriggerBuilder.newTrigger()

  2. .withIdentity(name, TRIGGER_GROUP)

  3. .withSchedule(

  4. CronScheduleBuilder.cronSchedule(time)

  5. .withMisfireHandlingInstructionDoNothing())

  6. .build();// 触发器名,触发器组,触发器时间设定

withMisfireHandlingInstructionDoNothing(所有的misfire不管,执行下一个周期的任务)

在quartz.properties配置文件中添加:

#这个时间大于10000(10秒)会导致MISFIRE_INSTRUCTION_DO_NOTHING不起作用。

org.quartz.jobStore.misfireThreshold = 1000

第二点:

配置文件中添加:jobStore

复制代码
org.quartz.scheduler.instanceName = DatartScheduleCluster

org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.misfireThreshold = 1000
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 5000

org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://172.29.60.145:3306:3306/datart?characterEncoding=utf-8&useSSL=false
# mysql8.0+ÒÔÉϰ汾ÅäÖÃ
# org.quartz.dataSource.myDS.URL=jdbc:mysql://localhost:3306/quartz?characterEncoding=utf-8&useSSL=false&serverTimezone = GMT
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password = 123456
org.quartz.dataSource.myDS.maxConnections = 5
//这个一定要加
spring.quartz.job-store-type= jdbc

第三个pom中添加依赖:

复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-quartz</artifactId>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.29</version>
</dependency>
相关推荐
武子康几秒前
大数据-239 离线数仓 - 广告业务实战:Flume 导入日志到 HDFS,并完成 Hive ODS/DWD 分层加载
大数据·后端·apache hive
摸鱼的春哥30 分钟前
Agent教程15:认识LangChain(中),状态机思维
前端·javascript·后端
Seven9734 分钟前
剑指offer-80、⼆叉树中和为某⼀值的路径(二)
java
风象南7 小时前
我把大脑开源给了AI
人工智能·后端
橙序员小站12 小时前
Agent Skill 是什么?一文讲透 Agent Skill 的设计与实现
前端·后端
怒放吧德德12 小时前
Netty 4.2 入门指南:从概念到第一个程序
java·后端·netty
雨中飘荡的记忆14 小时前
大流量下库存扣减的数据库瓶颈:Redis分片缓存解决方案
java·redis·后端
开心就好202515 小时前
UniApp开发应用多平台上架全流程:H5小程序iOS和Android
后端·ios
悟空码字15 小时前
告别“屎山代码”:AI 代码整洁器让老项目重获新生
后端·aigc·ai编程
小码哥_常15 小时前
大厂不宠@Transactional,背后藏着啥秘密?
后端