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

📄 scheduler.java

📁 定时器开源项目, 相对于 jcrontab, Quartz 算是更完整的一个项目, 随著开发的版本上来, 他已经脱离只是写在程序里面的计时器, 在指定的时间或区间, 处理所指定的事件. 也加入了 se
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright James House (c) 2001-2004 *  * All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: 1. * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. 2. Redistributions in * binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other * materials provided with the distribution. *  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.quartz;import java.util.Date;import java.util.List;import java.util.Set;/** * <p> * This is the main interface of a Quartz Scheduler. * </p> *  * <p> * A <code>Scheduler</code> maintains a registery of <code>{@link org.quartz.JobDetail}</code> * s and <code>{@link Trigger}</code>s. Once registered, the <code>Scheduler</code> * is responible for executing <code>Job</code> s when their associated * <code>Trigger</code> s fire (when their scheduled time arrives). * </p> *  * <p> * <code>Scheduler</code> instances are produced by a <code>{@link SchedulerFactory}</code>. * A scheduler that has already been created/initialized can be found and used * through the same factory that produced it. After a <code>Scheduler</code> * has been created, it must have its <code>start()</code> method called * before it will fire any <code>Job</code>s. * </p> *  * <p> * <code>Job</code> s are to be created by the 'client program', by defining * a class that implements the <code>{@link org.quartz.Job}</code> * interface. <code>{@link JobDetail}</code> objects are then created (also * by the client) to define a individual instances of the <code>Job</code>. * <code>JobDetail</code> instances can then be registered with the <code>Scheduler</code> * via the <code>scheduleJob(JobDetail, Trigger)</code> or <code>addJob(JobDetail, boolean)</code> * method. * </p> *  * <p> * <code>Trigger</code> s can then be defined to fire individual <code>Job</code> * instances based on given schedules. <code>SimpleTrigger</code> s are most * useful for one-time firings, or firing at an exact moment in time, with N * repeats with a given delay between them. <code>CronTrigger</code> s allow * scheduling based on time of day, day of week, day of month, and month of * year. * </p> *  * <p> * <code>Job</code> s and <code>Trigger</code> s have a name and group * associated with them, which should uniquely identify them within a single * <code>{@link Scheduler}</code>. The 'group' feature may be useful for * creating logical groupings or categorizations of <code>Jobs</code> s and * <code>Triggers</code>s. If you don't have need for assigning a group to a * given <code>Jobs</code> of <code>Triggers</code>, then you can use the * <code>DEFAULT_GROUP</code> constant defined on this interface. * </p> *  * <p> * Stored <code>Job</code> s can also be 'manually' triggered through the use * of the <code>triggerJob(String jobName, String jobGroup)</code> function. * </p> *  * <p> * Client programs may also be interested in the 'listener' interfaces that are * available from Quartz. The <code>{@link JobListener}</code> interface * provides notifications of <code>Job</code> executions. The <code>{@link TriggerListener}</code> * interface provides notifications of <code>Trigger</code> firings. The * <code>{@link SchedulerListener}</code> interface provides notifications of * <code>Scheduler</code> events and errors. * </p> *  * <p> * The setup/configuration of a <code>Scheduler</code> instance is very * customizable. Please consult the documentation distributed with Quartz. * </p> *  * @see Job * @see JobDetail * @see Trigger * @see JobListener * @see TriggerListener * @see SchedulerListener *  * @author James House * @author Sharada Jambula */public interface Scheduler {    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Constants.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    /**     * <p>     * A (possibly) usefull constant that can be used for specifying the group     * that <code>Job</code> and <code>Trigger</code> instances belong to.     * </p>     */    public static final String DEFAULT_GROUP = "DEFAULT";    /**     * <p>     * A constant <code>Trigger</code> group name used internally by the     * scheduler - clients should not use the value of this constant     * ("MANUAL_TRIGGER") for thename of a <code>Trigger</code>'s group.     * </p>     */    public static final String DEFAULT_MANUAL_TRIGGERS = "MANUAL_TRIGGER";    /**     * <p>     * A constant <code>Trigger</code> group name used internally by the     * scheduler - clients should not use the value of this constant     * ("RECOVERING_JOBS") for thename of a <code>Trigger</code>'s group.     * </p>     */    public static final String DEFAULT_RECOVERY_GROUP = "RECOVERING_JOBS";    /**     * <p>     * A constant <code>Trigger</code> group name used internally by the     * scheduler - clients should not use the value of this constant     * ("FAILED_OVER_JOBS") for thename of a <code>Trigger</code>'s group.     * </p>     */    public static final String DEFAULT_FAIL_OVER_GROUP = "FAILED_OVER_JOBS";    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Interface.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    /**     * <p>     * Returns the name of the <code>Scheduler</code>.     * </p>     */    public String getSchedulerName() throws SchedulerException;    /**     * <p>     * Returns the instance Id of the <code>Scheduler</code>.     * </p>     */    public String getSchedulerInstanceId() throws SchedulerException;    /**     * <p>     * Returns the <code>SchedulerContext</code> of the <code>Scheduler</code>.     * </p>     */    public SchedulerContext getContext() throws SchedulerException;    ///////////////////////////////////////////////////////////////////////////    ///    /// Schedululer State Management Methods    ///    ///////////////////////////////////////////////////////////////////////////    /**     * <p>     * Starts the <code>Scheduler</code>'s threads that fire <code>{@link Trigger}s</code>.     * </p>     *      * <p>     * All <code>{@link Trigger}s</code> that have misfired will be passed     * to the appropriate TriggerListener(s).     * </p>     *      * @throws SchedulerException     *           if <code>close()</code> has been called, or there is an     *           error within the <code>Scheduler</code>.     *      * @see #pause     * @see #shutdown     */    public void start() throws SchedulerException;    /**     * <p>     * Temporarily halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>.     * </p>     *      * <p>     * When <code>start()</code> is called (to un-pause), trigger misfire     * instructions will NOT be applied.     * </p>     *      * <p>     * The scheduler is not destroyed, and can be re-started at any time.     * </p>     *      * @see #start()     * @see #pauseAll()     */    public void pause() throws SchedulerException;    /**     * <p>     * Reports whether the <code>Scheduler</code> is paused.     * </p>     */    public boolean isPaused() throws SchedulerException;    /**     * <p>     * Halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>,     * and cleans up all resources associated with the Scheduler. Equivalent to     * <code>shutdown(false)</code>.     * </p>     *      * <p>     * The scheduler cannot be re-started.     * </p>     *      * @see #shutdown(boolean)     */    public void shutdown() throws SchedulerException;    /**     * <p>     * Halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>,     * and cleans up all resources associated with the Scheduler.     * </p>     *      * <p>     * The scheduler cannot be re-started.     * </p>     *      * @param waitForJobsToComplete     *          if <code>true</code> the scheduler will not allow this method     *          to return until all currently executing jobs have completed.     *      * @see #shutdown     */    public void shutdown(boolean waitForJobsToComplete)            throws SchedulerException;    /**     * <p>     * Reports whether the <code>Scheduler</code> has been shutdown.     * </p>     */    public boolean isShutdown() throws SchedulerException;    /**     * <p>     * Get a <code>SchedulerMetaData</code> object describiing the settings     * and capabilities of the scheduler instance.     * </p>     *      * <p>     * Note that the data returned is an 'instantaneous' snap-shot, and that as     * soon as it's returned, the meta data values may be different.     * </p>     */    public SchedulerMetaData getMetaData() throws SchedulerException;    /**     * <p>     * Return a list of <code>JobExecutionContext</code> objects that     * represent all currently executing Jobs.     * </p>     *      * <p>     * Note that the list returned is an 'instantaneous' snap-shot, and that as     * soon as it's returned, the true list of executing jobs may be different.     * Also please read the doc associated with <code>JobExecutionContext</code>-     * especially if you're using RMI.     * </p>     *      * @see JobExecutionContext     */    public List getCurrentlyExecutingJobs() throws SchedulerException;    ///////////////////////////////////////////////////////////////////////////    ///    /// Scheduling-related Methods    ///    ///////////////////////////////////////////////////////////////////////////    /**     * <p>     * Add the given <code>{@link org.quartz.JobDetail}</code> to the     * Scheduler, and associate the given <code>{@link Trigger}</code> with     * it.     * </p>     *      * <p>     * If the given Trigger does not reference any <code>Job</code>, then it     * will be set to reference the Job passed with it into this method.     * </p>     *      * @throws SchedulerException     *           if the Job or Trigger cannot be added to the Scheduler, or     *           there is an internal Scheduler error.     */    public Date scheduleJob(JobDetail jobDetail, Trigger trigger)            throws SchedulerException;    /**     * <p>     * Schedule the given <code>{@link org.quartz.Trigger}</code> with the     * <code>Job</code> identified by the <code>Trigger</code>'s settings.     * </p>     *      * @throws SchedulerException     *           if the indicated Job does not exist, or the Trigger cannot be     *           added to the Scheduler, or there is an internal Scheduler     *           error.     */    public Date scheduleJob(Trigger trigger) throws SchedulerException;    /**     * <p>     * Remove the indicated <code>{@link Trigger}</code> from the scheduler.     * </p>     */    public boolean unscheduleJob(String triggerName, String groupName)            throws SchedulerException;    /**     * <p>     * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the     * given name, and store the new given one - which must be associated     * with the same job - however, the new trigger need not have the same      * name as the old trigger.     * </p>     *      * @param triggerName     *          The name of the <code>Trigger</code> to be replaced.     * @param groupName     *          The group name of the <code>Trigger</code> to be replaced.     * @param newTrigger     *          The new <code>Trigger</code> to be stored.     * @return <code>null</code> if a <code>Trigger</code> with the given     *         name & group was not found and removed from the store, otherwise     *         the first fire time of the newly scheduled trigger.     */    public Date rescheduleJob(String triggerName,            String groupName, Trigger newTrigger) throws SchedulerException;        /**     * <p>     * Add the given <code>Job</code> to the Scheduler - with no associated     * <code>Trigger</code>. The <code>Job</code> will be 'dormant' until     * it is scheduled with a <code>Trigger</code>, or <code>Scheduler.triggerJob()</code>     * is called for it.     * </p>     *      * <p>     * The <code>Job</code> must by definition be 'durable', if it is not,     * SchedulerException will be thrown.     * </p>     *      * @throws SchedulerException     *           if there is an internal Scheduler error, or if the Job is not     *           durable, or a Job with the same name already exists, and     *           <code>replace</code> is <code>false</code>.     */    public void addJob(JobDetail jobDetail, boolean replace)            throws SchedulerException;    /**     * <p>     * Delete the identified <code>Job</code> from the Scheduler - and any     * associated <code>Trigger</code>s.     * </p>     *      * @return true if the Job was found and deleted.     * @throws SchedulerException     *           if there is an internal Scheduler error.     */    public boolean deleteJob(String jobName, String groupName)            throws SchedulerException;    /**     * <p>     * Trigger the identified <code>{@link org.quartz.JobDetail}</code>     * (execute it now) - the generated trigger will be non-volatile.     * </p>     */    public void triggerJob(String jobName, String groupName)            throws SchedulerException;    /**     * <p>     * Trigger the identified <code>{@link org.quartz.JobDetail}</code>     * (execute it now) - the generated trigger will be volatile.     * </p>     */    public void triggerJobWithVolatileTrigger(String jobName, String groupName)            throws SchedulerException;    /**     * <p>     * Pause the <code>{@link org.quartz.JobDetail}</code> with the given     * name - by pausing all of its current <code>Trigger</code>s.     * </p>     *      * @see #resumeJob(String, String)     */    public void pauseJob(String jobName, String groupName)            throws SchedulerException;    /**     * <p>     * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the     * given group - by pausing all of their <code>Trigger</code>s.     * </p>     *      * <p>     * The Scheduler will "remember" that the group is paused, and impose the     * pause on any new jobs that are added to the group while the group is     * paused.     * </p>     *      * @see #resumeJobGroup(String)     */    public void pauseJobGroup(String groupName) throws SchedulerException;    /**     * <p>     * Pause the <code>{@link Trigger}</code> with the given name.     * </p>

⌨️ 快捷键说明

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