写在前面
SpringBoot 集成Quartz框架时,数据保存方式使用PostgreSQL进行数据库持久化。
报错如下:
Couldn’t acquire next trigger: Couldn’t retrieve trigger: 不良的类型值 long : \x
参数配置
#============================================================================
# 1. 基本配置
#============================================================================
# 调度标识名, 集群中每一个实例都必须使用相同的名称
org.quartz.scheduler.instanceName = SERVICEX-SCHEDULER-INSTANCE
# ID设置为自动获取, 每一个实例不能相同
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# 2. 调度器线程池配置
#============================================================================
# 线程池的实现类, 一般使用SimpleThreadPool即可满足需求
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
# 指定线程数无默认值, 至少为1
org.quartz.threadPool.threadCount = 20
# 设置线程的优先级(最大为java.lang.Thread.MAX_PRIORITY 10,最小为Thread.MIN_PRIORITY 1,默认为5)
org.quartz.threadPool.threadPriority = 5
#============================================================================
# 3. 作业存储配置
#============================================================================
# 数据保存方式为数据库持久化
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
# 是否加入集群
org.quartz.jobStore.isClustered = true
# 检查集群节点状态的频率, 默认值是 15000(即15秒)
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 1
org.quartz.jobStore.txIsolationLevelSerializable = true
# 设置调度引擎对触发器超时的忍耐时间 (单位毫秒)
org.quartz.jobStore.misfireThreshold = 12000
# 表的前缀,默认QRTZ_
org.quartz.jobStore.tablePrefix = QRTZ_
错误信息
2022-09-16 10:19:50 | ERROR | SERVICEX-SCHEDULER-FACTORY_QuartzSchedulerThread | org.quartz.core.ErrorLogger | An error occurred while scanning for the next triggers to fire.
org.quartz.JobPersistenceException: Couldn't acquire next trigger: Couldn't retrieve trigger: 不良的类型值 long : \x
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2923)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$41.execute(JobStoreSupport.java:2805)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$41.execute(JobStoreSupport.java:2803)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3864)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTriggers(JobStoreSupport.java:2802)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:287)
Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: 不良的类型值 long : \x
at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1538)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.acquireNextTrigger(JobStoreSupport.java:2854)
... 5 common frames omitted
Caused by: org.postgresql.util.PSQLException: 不良的类型值 long : \x
at org.postgresql.jdbc.PgResultSet.toLong(PgResultSet.java:3043)
at org.postgresql.jdbc.PgResultSet.getLong(PgResultSet.java:2216)
at org.postgresql.jdbc.PgResultSet.getBlob(PgResultSet.java:428)
at org.postgresql.jdbc.PgResultSet.getBlob(PgResultSet.java:414)
at com.alibaba.druid.pool.DruidPooledResultSet.getBlob(DruidPooledResultSet.java:1169)
at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.getObjectFromBlob(StdJDBCDelegate.java:3190)
at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectTrigger(StdJDBCDelegate.java:1780)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1536)
... 6 common frames omitted
原因描述
由于StdJDBCDelegate在读取BLOB时存在问题,需要使用与数据库相对应的驱动。
解决方案
指定数据库的驱动,如果不指定则默认使用的驱动为:org.quartz.impl.jdbcjobstore.StdJDBCDelegate
# 数据库驱动
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate