我使用的是Weblogic + Spring + quartz。
Quartz配置为使用JobStoreCMT。
我注意到JobStoreCMT在安排作业时会在石英表上获取数据库锁。
以下是JobStoreCMT片段
protected Object executeInLock(
String lockName,
TransactionCallback txCallback) throws JobPersistenceException {
boolean transOwner = false;
Connection conn = null;
try {
if (lockName != null) {
// If we aren't using db locks, then delay getting DB connection
// until after aquiring the lock since it isn't needed.
if (getLockHandler().requiresConnection()) {
conn = getConnection();
}
transOwner = getLockHandler().obtainLock(conn, lockName);
}
if (conn == null) {
conn = getConnection();
}
return txCallback.execute(conn);
} finally {
try {
releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);
} finally {
cleanupConnection(conn);
}
}
}
在这个方法之后,我在数据库的石英表中看到了我安排的触发器和作业。
我的问题是为什么Quartz需要在此阶段锁定数据库级别?
我会看到在开始执行,完成等工作时需要锁定。
谢谢
答案 0 :(得分:0)
我发现了一些解决了我的问题的设置:
setLockOnInsert为false,因为默认情况下为true。
public void setLockOnInsert(boolean lockOnInsert)
插入新作业/触发器时是否获取锁定。默认为true,这是最安全的 - 某些db(例如MS SQLServer)似乎要求这样做以避免高负载下的死锁,而其他人似乎没有做好。 将此属性设置为false将在添加新作业和触发器期间显着提高性能。
+ org.quartz.jobStore.acquireTriggersWithinLock我把它设置为false(默认情况下),不是我最初配置的那样。