第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Quartz作業(yè)注解@DisallowConcurrentExecution實(shí)現(xiàn)

Quartz作業(yè)注解@DisallowConcurrentExecution實(shí)現(xiàn)

森欄 2023-08-09 15:12:05
我是石英新手。我發(fā)現(xiàn)了@DisallowConcurrentExecutionquartz庫(kù)提供的注釋,文檔說(shuō):'An annotation that marks a {@link Job} class as one that must not have multiple instances executed concurrently (where instance is based-upon a {@link JobDetail} definition - or in other words based upon a {@link JobKey}).'則DisallowConcurrentExecution.java寫為:@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)public @interface DisallowConcurrentExecution {}但是,我找不到實(shí)際處理同一作業(yè)不并發(fā)執(zhí)行的實(shí)現(xiàn)。這對(duì)我來(lái)說(shuō)是新的,所以有人可以幫助我解釋內(nèi)部實(shí)現(xiàn)邏輯。我試圖查找用法,但只在課堂上找到了它MethodInvokingJobDetailFactoryBean.java
查看完整描述

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);

    }


}


查看完整回答
反對(duì) 回復(fù) 2023-08-09
  • 1 回答
  • 0 關(guān)注
  • 446 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)