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

📄 directschedulerfactory.java

📁 Quartz is a full-featured, open source job scheduling system that can be integrated with, or used al
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  * Copyright 2004-2005 OpenSymphony  *  * Licensed under the Apache License, Version 2.0 (the "License"); you may not  * use this file except in compliance with the License. You may obtain a copy  * of the License at  *  *   http://www.apache.org/licenses/LICENSE-2.0  *    * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the  * License for the specific language governing permissions and limitations  * under the License. *  *//* * Previously Copyright (c) 2001-2004 James House */package org.quartz.impl;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.quartz.Scheduler;import org.quartz.SchedulerException;import org.quartz.SchedulerFactory;import org.quartz.core.JobRunShellFactory;import org.quartz.core.QuartzScheduler;import org.quartz.core.QuartzSchedulerResources;import org.quartz.core.SchedulingContext;import org.quartz.simpl.CascadingClassLoadHelper;import org.quartz.simpl.RAMJobStore;import org.quartz.simpl.SimpleThreadPool;import org.quartz.spi.ClassLoadHelper;import org.quartz.spi.JobStore;import org.quartz.spi.SchedulerPlugin;import org.quartz.spi.ThreadPool;import java.util.Collection;import java.util.Iterator;import java.util.Map;/** * <p> * A singleton implementation of <code>{@link org.quartz.SchedulerFactory}</code>. * </p> *  * <p> * Here are some examples of using this class: * </p> * <p> * To create a scheduler that does not write anything to the database (is not * persistent), you can call <code>createVolatileScheduler</code>: *  * <pre> *  DirectSchedulerFactory.getInstance().createVolatileScheduler(10); // 10 threads * // don't forget to start the scheduler: DirectSchedulerFactory.getInstance().getScheduler().start(); * </pre> *  *  * <p> * Several create methods are provided for convenience. All create methods * eventually end up calling the create method with all the parameters: * </p> *  * <pre> *  public void createScheduler(String schedulerName, String schedulerInstanceId, ThreadPool threadPool, JobStore jobStore, String rmiRegistryHost, int rmiRegistryPort) * </pre> *  *  * <p> * Here is an example of using this method: * </p> *  * *  * <pre>// create the thread pool SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads, Thread.NORM_PRIORITY); threadPool.initialize(); * // create the job store JobStore jobStore = new RAMJobStore(); jobStore.initialize(); *  *  DirectSchedulerFactory.getInstance().createScheduler("My Quartz Scheduler", "My Instance", threadPool, jobStore, "localhost", 1099); * // don't forget to start the scheduler: DirectSchedulerFactory.getInstance().getScheduler("My Quartz Scheduler", "My Instance").start(); * </pre> *  *  * <p> * You can also use a JDBCJobStore instead of the RAMJobStore: * </p> *  * <pre> *  DBConnectionManager.getInstance().addConnectionProvider("someDatasource", new JNDIConnectionProvider("someDatasourceJNDIName")); *  *  JDBCJobStore jdbcJobStore = new JDBCJobStore(); jdbcJobStore.setDataSource("someDatasource"); jdbcJobStore.setPostgresStyleBlobs(true); jdbcJobStore.setTablePrefix("QRTZ_"); jdbcJobStore.setInstanceId("My Instance"); jdbcJobStore.initialize(); * </pre> *  * @author Mohammad Rezaei * @author James House *  * @see JobStore * @see ThreadPool */public class DirectSchedulerFactory implements SchedulerFactory {    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Constants.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    public static final String DEFAULT_INSTANCE_ID = "SIMPLE_NON_CLUSTERED";    public static final String DEFAULT_SCHEDULER_NAME = "SimpleQuartzScheduler";    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Data members.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    private boolean initialized = false;    private static DirectSchedulerFactory instance = new DirectSchedulerFactory();    private final Log log = LogFactory.getLog(getClass());    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Constructors.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    protected Log getLog() {        return log;    }    /**     * Constructor     */    protected DirectSchedulerFactory() {    }    /*     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     *      * Interface.     *      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     */    public static DirectSchedulerFactory getInstance() {        return instance;    }    /**     * Creates an in memory job store (<code>{@link RAMJobStore}</code>)     * The thread priority is set to Thread.NORM_PRIORITY     *      * @param maxThreads     *          The number of threads in the thread pool     * @throws SchedulerException     *           if initialization failed.     */    public void createVolatileScheduler(int maxThreads)        throws SchedulerException {        SimpleThreadPool threadPool = new SimpleThreadPool(maxThreads,                Thread.NORM_PRIORITY);        threadPool.initialize();        JobStore jobStore = new RAMJobStore();        this.createScheduler(threadPool, jobStore);    }    /**     * @deprecated see correctly spelled method.     * @see #createVolatileScheduler(int)     */    public void createVolatileSchduler(int maxThreads)        throws SchedulerException {        createVolatileScheduler(maxThreads);    }        /**     * Creates a proxy to a remote scheduler. This scheduler can be retrieved     * via {@link DirectSchedulerFactory#getScheduler()}     *      * @param rmiHost     *          The hostname for remote scheduler     * @param rmiPort     *          Port for the remote scheduler. The default RMI port is 1099.     * @throws SchedulerException     *           if the remote scheduler could not be reached.     */    public void createRemoteScheduler(String rmiHost, int rmiPort)        throws SchedulerException {        createRemoteScheduler(DEFAULT_SCHEDULER_NAME, DEFAULT_INSTANCE_ID,                rmiHost, rmiPort);        initialized = true;    }    /**     * Same as     * {@link DirectSchedulerFactory#createRemoteScheduler(String rmiHost, int rmiPort)},     * with the addition of specifying the scheduler name and instance ID. This     * scheduler can only be retrieved via     * {@link DirectSchedulerFactory#getScheduler(String)}     *      * @param schedulerName     *          The name for the scheduler.     * @param schedulerInstanceId     *          The instance ID for the scheduler.     * @param rmiHost     *          The hostname for remote scheduler     * @param rmiPort     *          Port for the remote scheduler. The default RMI port is 1099.     * @throws SchedulerException     *           if the remote scheduler could not be reached.     */    public void createRemoteScheduler(String schedulerName,            String schedulerInstanceId, String rmiHost, int rmiPort)        throws SchedulerException {        createRemoteScheduler(schedulerName,                schedulerInstanceId, null, rmiHost, rmiPort);    }    /**     * Same as     * {@link DirectSchedulerFactory#createRemoteScheduler(String rmiHost, int rmiPort)},     * with the addition of specifying the scheduler name, instance ID, and rmi      * bind name. This scheduler can only be retrieved via     * {@link DirectSchedulerFactory#getScheduler(String)}     *      * @param schedulerName     *          The name for the scheduler.     * @param schedulerInstanceId     *          The instance ID for the scheduler.     * @param rmiBindName      *          The name of the remote scheduler in the RMI repository.  If null     *          defaults to the generated unique identifier.      * @param rmiHost     *          The hostname for remote scheduler     * @param rmiPort     *          Port for the remote scheduler. The default RMI port is 1099.

⌨️ 快捷键说明

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