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

📄 intervallistener.java

📁 Quartz1.6的例子
💻 JAVA
字号:
/* =================================
 * 文  件: IntervalListener.java
 * 公  司: 南京中兴软件有限责任公司     
 * 版  权: Copyright (c) 2008      
 * 日  期: Mar 30, 2008                
 * ================================= */

package org.quartz.examples.example15;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.examples.example9.Job1Listener;

/**
 * <p />描    述:TODO 请在这里写下描述
 * <p />@version 1.0.0
 * <p />@author  zhangzb158115
 * <p />
 * <p />========= 修改记录[BEGIN] =========
 * <p />修改日期:
 * <p />修 改 人:
 * <p />修改版本:
 * <p />修改原因:
 * <p />修改内容:
 * <p />========= 修改记录[ END ] =========
 * <p />
 */
public class IntervalListener implements JobListener {
    private static Log _log = LogFactory.getLog(IntervalListener.class);

    private long pauseTimeInterval;

    private long runTimeInterval;

    private long startPauseTime;

    private long startRunTime;

    public IntervalListener() {
        pauseTimeInterval = 10L * 1000L;
        runTimeInterval = 5L * 1000L;
        startPauseTime = 0L;
        startRunTime = 0L;
    }

    public String getName() {
        return "GivenIntervalListener";
    }

    /**
     * End
     */
    public void jobExecutionVetoed(JobExecutionContext context) {
        _log.error("IntervalListener says: Job Execution was vetoed.");
    }

    /**
     * Before
     */
    public void jobToBeExecuted(JobExecutionContext context) {
        _log.error("IntervalListener says: Job Is about to be executed.");
        long currentTime = System.currentTimeMillis();
        Scheduler sched = context.getScheduler();
        boolean pauseState = false, state = false;
        try {
            pauseState = sched.isInStandbyMode();
            state = sched.isStarted();
        } catch (SchedulerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        _log.fatal("pauseState:" + pauseState + ",state:" + state);
        if (state && !pauseState) {
            if (startRunTime == 0) {
                startRunTime = context.getFireTime().getTime();
            }
            _log.fatal("currentTime - startRunTime:" + (currentTime - startRunTime));
            if (currentTime - startRunTime >= runTimeInterval) {
                try {
                    sched.standby();
                    startPauseTime = currentTime;
                    _log.fatal("===========Be about to be PAUSING status From RUNNING status .");
                } catch (SchedulerException e) {
                    _log.fatal("FAILED===========Be about to be PAUSING status From RUNNING status .");
                    e.printStackTrace();
                }
            }
        }
        if (pauseState) {
            if (startPauseTime == 0) {
                startPauseTime = currentTime;
            }
            _log.fatal("currentTime - startPauseTime:"+(currentTime - startPauseTime));
            if (currentTime - startPauseTime >= pauseTimeInterval) {
                try {
                    sched.start();
                    startRunTime = currentTime;
                    _log.fatal("===========Be about to be RUNNING status From PAUSING status....");
                } catch (SchedulerException e) {
                    _log.fatal("FATAL===========Be about to be RUNNING status From PAUSING status....");
                    e.printStackTrace();
                }
            }
        }

    }

    /**
     * After
     */
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        _log.error("IntervalListener says: Job was executed.");

    }

}

⌨️ 快捷键说明

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