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

📄 quartzserver.java

📁 定时器开源项目, 相对于 jcrontab, Quartz 算是更完整的一个项目, 随著开发的版本上来, 他已经脱离只是写在程序里面的计时器, 在指定的时间或区间, 处理所指定的事件. 也加入了 se
💻 JAVA
字号:
/* * 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.impl;import java.io.BufferedReader;import java.io.InputStreamReader;import org.quartz.Scheduler;import org.quartz.SchedulerException;import org.quartz.SchedulerFactory;import org.quartz.Trigger;/** * <p> * Instantiates an instance of Quartz Scheduler as a stand-alone program, if * the scheduler is configured for RMI it will be made available. * </p> *  * <p> * The main() method of this class currently accepts 0 or 1 arguemtns, if there * is an argument, and its value is <code>"console"</code>, then the program * will print a short message on the console (std-out) and wait for the user to * type "exit" - at which time the scheduler will be shutdown. * </p> *  * <p> * Future versions of this server should allow additional configuration for * responding to scheduler events by allowing the user to specify <code>{@link org.quartz.JobListener}</code>, * <code>{@link org.quartz.TriggerListener}</code> and <code>{@link org.quartz.SchedulerListener}</code> * classes. * </p> *  * <p> * Please read the Quartz FAQ entries about RMI before asking questions in the * forums or mail-lists. * </p> *  * @author James House */public class QuartzServer implements org.quartz.SchedulerListener {    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Data members.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    private Scheduler sched = null;    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Constructors.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    QuartzServer() {    }    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Interface.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    public void serve(SchedulerFactory schedFact, boolean console)            throws Exception {        sched = schedFact.getScheduler();        sched.start();        try {            Thread.sleep(3000l);        } catch (Exception ignore) {        }        System.out.println("\n*** The scheduler successfully started.");        if (console) {            System.out.println("\n");            System.out                    .println("The scheduler will now run until you type \"exit\"");            System.out                    .println("   If it was configured to export itself via RMI,");            System.out.println("   then other process may now use it.");            BufferedReader rdr = new BufferedReader(new InputStreamReader(                    System.in));            while (true) {                System.out.print("Type 'exit' to shutdown the server: ");                if ("exit".equals(rdr.readLine())) {                    break;                }            }            System.out.println("\n...Shutting down server...");            sched.shutdown(true);        }    }    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * SchedulerListener Interface.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link org.quartz.JobDetail}</code>     * is scheduled.     * </p>     */    public void jobScheduled(Trigger trigger) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link org.quartz.JobDetail}</code>     * is unscheduled.     * </p>     */    public void jobUnscheduled(String triggerName, String triggerGroup) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link Trigger}</code>     * has reached the condition in which it will never fire again.     * </p>     */    public void triggerFinalized(Trigger trigger) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link Trigger}</code>     * or group of <code>{@link Trigger}s</code> has been paused.     * </p>     *      * <p>     * If a group was paused, then the <code>triggerName</code> parameter     * will be null.     * </p>     */    public void triggersPaused(String triggerName, String triggerGroup) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link Trigger}</code>     * or group of <code>{@link Trigger}s</code> has been un-paused.     * </p>     *      * <p>     * If a group was resumed, then the <code>triggerName</code> parameter     * will be null.     * </p>     */    public void triggersResumed(String triggerName, String triggerGroup) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link org.quartz.JobDetail}</code>     * or group of <code>{@link org.quartz.JobDetail}s</code> has been     * paused.     * </p>     *      * <p>     * If a group was paused, then the <code>jobName</code> parameter will be     * null.     * </p>     */    public void jobsPaused(String jobName, String jobGroup) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a <code>{@link org.quartz.JobDetail}</code>     * or group of <code>{@link org.quartz.JobDetail}s</code> has been     * un-paused.     * </p>     *      * <p>     * If a group was paused, then the <code>jobName</code> parameter will be     * null.     * </p>     */    public void jobsResumed(String jobName, String jobGroup) {    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> when a serious error has     * occured within the scheduler - such as repeated failures in the <code>JobStore</code>,     * or the inability to instantiate a <code>Job</code> instance when its     * <code>Trigger</code> has fired.     * </p>     *      * <p>     * The <code>getErrorCode()</code> method of the given SchedulerException     * can be used to determine more specific information about the type of     * error that was encountered.     * </p>     */    public void schedulerError(String msg, SchedulerException cause) {        System.err.println("*** " + msg);        cause.printStackTrace();    }    /**     * <p>     * Called by the <code>{@link Scheduler}</code> to inform the listener     * that it has shutdown.     * </p>     */    public void schedulerShutdown() {        System.out.println("\n*** The scheduler is now shutdown.");        sched = null;    }    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Main Method.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    public static void main(String[] args) throws Exception {        //    //Configure Log4J        //    org.apache.log4j.PropertyConfigurator.configure(        //      System.getProperty("log4jConfigFile", "log4j.properties"));        if (System.getSecurityManager() == null) {            System.setSecurityManager(new java.rmi.RMISecurityManager());        }        try {            QuartzServer server = new QuartzServer();            if (args.length == 0) server.serve(                    new org.quartz.impl.StdSchedulerFactory(), false);            else if (args.length == 1 && args[0].equalsIgnoreCase("console")) server                    .serve(new org.quartz.impl.StdSchedulerFactory(), true);            else {                System.err.println("\nUsage: QuartzServer [console]");            }        } catch (Exception e) {            e.printStackTrace();        }    }}

⌨️ 快捷键说明

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