1 回答

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊
我不參與石英項(xiàng)目。我在這里的所有評(píng)論都來(lái)自我出于好奇而對(duì)此事的調(diào)查,可能會(huì)遺漏一些信息。
首先要知道的是,JobDetailImpl 將檢查注釋是否存在并在方法中提供此信息。
/**
* @return whether the associated Job class carries the {@link DisallowConcurrentExecution} annotation.
*/
public boolean isConcurrentExectionDisallowed() {
return ClassUtils.isAnnotationPresent(jobClass, DisallowConcurrentExecution.class);
}
然后你可以看到這個(gè)方法在系統(tǒng)的不同部分被檢查。
例如,JobStoreSupport 在此處檢查它,如果存在注釋,則它會(huì)檢查塊狀態(tài):
if (job.isConcurrentExectionDisallowed() && !recovering) {
state = checkBlockedState(conn, job.getKey(), state);
}
這里是實(shí)際驗(yàn)證發(fā)生的地方,并讓 Quartz 決定在該實(shí)例上運(yùn)行或不運(yùn)行作業(yè)。
org.quartz.impl.jdbcjobstore.JobStoreSupport#checkBlockedState
/**
* Determines if a Trigger for the given job should be blocked.
* State can only transition to STATE_PAUSED_BLOCKED/BLOCKED from
* PAUSED/STATE_WAITING respectively.
*
* @return STATE_PAUSED_BLOCKED, BLOCKED, or the currentState.
*/
protected String checkBlockedState(
Connection conn, JobKey jobKey, String currentState)
throws JobPersistenceException {
// State can only transition to BLOCKED from PAUSED or WAITING.
if ((!currentState.equals(STATE_WAITING)) &&
(!currentState.equals(STATE_PAUSED))) {
return currentState;
}
try {
List<FiredTriggerRecord> lst = getDelegate().selectFiredTriggerRecordsByJob(conn,
jobKey.getName(), jobKey.getGroup());
if (lst.size() > 0) {
FiredTriggerRecord rec = lst.get(0);
if (rec.isJobDisallowsConcurrentExecution()) { // OLD_TODO: worry about failed/recovering/volatile job states?
return (STATE_PAUSED.equals(currentState)) ? STATE_PAUSED_BLOCKED : STATE_BLOCKED;
}
}
return currentState;
} catch (SQLException e) {
throw new JobPersistenceException(
"Couldn't determine if trigger should be in a blocked state '"
+ jobKey + "': "
+ e.getMessage(), e);
}
}
添加回答
舉報(bào)