⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jobstoretx.java

📁 定时器开源项目, 相对于 jcrontab, Quartz 算是更完整的一个项目, 随著开发的版本上来, 他已经脱离只是写在程序里面的计时器, 在指定的时间或区间, 处理所指定的事件. 也加入了 se
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            Trigger[] triggers = getTriggersForJob(conn, ctxt, jobName,                    groupName);            for (int j = 0; j < triggers.length; j++) {                resumeTrigger(conn, ctxt, triggers[j].getName(), triggers[j]                        .getGroup());            }            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    /**     * <p>     * Resume (un-pause) all of the <code>{@link org.quartz.Job}s</code> in     * the given group.     * </p>     *      * <p>     * If any of the <code>Job</code> s had <code>Trigger</code> s that     * missed one or more fire-times, then the <code>Trigger</code>'s     * misfire instruction will be applied.     * </p>     *      * @see #pauseJobGroup(SchedulingContext, String)     */    public void resumeJobGroup(SchedulingContext ctxt, String groupName)            throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            String[] jobNames = getJobNames(conn, ctxt, groupName);            for (int i = 0; i < jobNames.length; i++) {                Trigger[] triggers = getTriggersForJob(conn, ctxt, jobNames[i],                        groupName);                for (int j = 0; j < triggers.length; j++) {                    resumeTrigger(conn, ctxt, triggers[j].getName(),                            triggers[j].getGroup());                }            }            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    /**     * <p>     * Pause all triggers - equivalent of calling <code>pauseTriggerGroup(group)</code>     * on every group.     * </p>     *      * <p>     * When <code>resumeAll()</code> is called (to un-pause), trigger misfire     * instructions WILL be applied.     * </p>     *      * @see #resumeAll(SchedulingContext)     * @see #pauseTriggerGroup(SchedulingContext, String)     */    public void pauseAll(SchedulingContext ctxt) throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            pauseAll(conn, ctxt);            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    /**     * <p>     * Resume (un-pause) all triggers - equivalent of calling <code>resumeTriggerGroup(group)</code>     * on every group.     * </p>     *      * <p>     * If any <code>Trigger</code> missed one or more fire-times, then the     * <code>Trigger</code>'s misfire instruction will be applied.     * </p>     *      * @see #pauseAll(SchedulingContext)     */    public void resumeAll(SchedulingContext ctxt)            throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            resumeAll(conn, ctxt);            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    //---------------------------------------------------------------------------    // trigger firing methods    //---------------------------------------------------------------------------    /**     * <p>     * Get a handle to the next trigger to be fired, and mark it as 'reserved'     * by the calling scheduler.     * </p>     *      * @see #releaseAcquiredTrigger(SchedulingContext, Trigger)     */    public Trigger acquireNextTrigger(SchedulingContext ctxt)            throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            Trigger trigger = acquireNextTrigger(conn, ctxt);            commitConnection(conn);            return trigger;        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    /**     * <p>     * Inform the <code>JobStore</code> that the scheduler no longer plans to     * fire the given <code>Trigger</code>, that it had previously acquired     * (reserved).     * </p>     */    public void releaseAcquiredTrigger(SchedulingContext ctxt, Trigger trigger)            throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            releaseAcquiredTrigger(conn, ctxt, trigger);            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    /**     * <p>     * Inform the <code>JobStore</code> that the scheduler is now firing the     * given <code>Trigger</code> (executing its associated <code>Job</code>),     * that it had previously acquired (reserved).     * </p>     *      * @return null if the trigger or it's job or calendar no longer exist, or     *         if the trigger was not successfully put into the 'executing'     *         state.     */    public TriggerFiredBundle triggerFired(SchedulingContext ctxt,            Trigger trigger) throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            TriggerFiredBundle tfb = null;            JobPersistenceException err = null;            try {                tfb = triggerFired(conn, ctxt, trigger);            } catch (JobPersistenceException jpe) {                if (jpe.getErrorCode() != SchedulerException.ERR_PERSISTENCE_JOB_DOES_NOT_EXIST)                        throw jpe;                err = jpe;            }            commitConnection(conn);            if (err != null) throw err;            return tfb;        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    /**     * <p>     * Inform the <code>JobStore</code> that the scheduler has completed the     * firing of the given <code>Trigger</code> (and the execution its     * associated <code>Job</code>), and that the <code>{@link org.quartz.JobDataMap}</code>     * in the given <code>JobDetail</code> should be updated if the <code>Job</code>     * is stateful.     * </p>     */    public void triggeredJobComplete(SchedulingContext ctxt, Trigger trigger,            JobDetail jobDetail, int triggerInstCode)            throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            triggeredJobComplete(conn, ctxt, trigger, jobDetail,                    triggerInstCode);            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    protected boolean doRecoverMisfires() throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        boolean moreToDo = false;        try {            getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);            transOwner = true;            //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);            try {                moreToDo = recoverMisfiredJobs(conn, false);            } catch (Exception e) {                throw new JobPersistenceException(e.getMessage(), e);            }            commitConnection(conn);            return moreToDo;        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);                      closeConnection(conn);        }    }    protected boolean doCheckin() throws JobPersistenceException {        Connection conn = getConnection();        boolean transOwner = false;        boolean transStateOwner = false;        boolean recovered = false;        try {            getLockHandler().obtainLock(conn, LOCK_STATE_ACCESS);            transStateOwner = true;            List failedRecords = clusterCheckIn(conn);            if (failedRecords.size() > 0) {                getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS);                //getLockHandler().obtainLock(conn, LOCK_JOB_ACCESS);                transOwner = true;                clusterRecover(conn, failedRecords);                recovered = true;            }            commitConnection(conn);        } catch (JobPersistenceException e) {            rollbackConnection(conn);            throw e;        } finally {            releaseLock(conn, LOCK_TRIGGER_ACCESS, transOwner);            releaseLock(conn, LOCK_STATE_ACCESS, transStateOwner);                        closeConnection(conn);        }        firstCheckIn = false;        return recovered;    }}// EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -