当多个weblogic节点发布时,定时框架采用的是SELECT * FROM SP_QRTZ_LOCKS WHERE LOCK_NAME = :1 FOR UPDATE获取锁的形式,当能锁住记录则执行定时任务。多个节点执行会产生大量的行锁。为了解决这个问题SELECT * FROM SP_QRTZ_LOCKS WHERE LOCK_NAME = :1 FOR UPDATE NOWAIT ,可以解决锁的问题,但会导致任务出错退出。最后通过SELECT * FROM {0}LOCKS UPDLOCK WHERE SCHED_NAME = {1} AND LOCK_NAME = ? FOR UPDATE SKIP LOCKED 可完美解决。
quartz: properties: org: quartz: scheduler: #实例名称,缺省QuartzScheduler instanceName: myScheduler instanceId: AUTO jobStore: class: org.quartz.impl.jdbcjobstore.JobStoreTX # Driver代理 driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate #表前缀 tablePrefix: QRTZ_ isClustered: false clusterCheckinInterval: 10000 useProperties: false ##################################################################### #在LOCKS表中选择一行,然后在这一行放一把锁。默认为“SELECT * FROM #{0}LOCKS WHERE SCHED_NAME ={1} AND LOCK_NAME = ? FOR UPDATE”, #这对于大多数数据库都适用。“{0}”由上面的配置的TABLE_PREFIX在运行 #时替换,而“{1}”由scheduler的名字替换。 ##################################################################### selectWithLockSQL : SELECT * FROM {0}LOCKS UPDLOCK WHERE SCHED_NAME = {1} AND LOCK_NAME = ? FOR UPDATE SKIP LOCKED threadPool: class: org.quartz.simpl.SimpleThreadPool threadCount: 10 threadPriority: 5 threadsInheritContextClassLoaderOfInitializingThread: true job-store-type: jdbc