<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    默了默

    java hibernate struts2 spring
       :: 首頁(yè) ::  ::  ::  :: 管理

    A ServletContextListner that can be used to initialize Quartz.

    配置和集成 Quartz 到 Web 應(yīng)用的一種方式。從 2.3 版本的 Servlet API 開(kāi)始,能創(chuàng)建監(jiān)聽(tīng)器,由容器在其生命周期中的某個(gè)特定時(shí)間回調(diào)。其中的一個(gè)監(jiān)聽(tīng)器接口叫做 java.servlet.ServletContextListener,它包括有兩個(gè)方法:

    public void contextInitialized(ServletContextEvent sce);
    public void contextDestroyed(ServeltContextEvent sce);

    容器會(huì)在啟動(dòng)和關(guān)閉的時(shí)候相應(yīng)的調(diào)用這兩個(gè)方法。這就可以在 contextInitialized() 方法中初始化 Quartz Scheduler,并通過(guò) contextDestroyed() 方法關(guān)閉它。
    下面是QuartzInitializerListener 源碼:

    /*
     * 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.ee.servlet;

    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;

    import org.quartz.Scheduler;
    import org.quartz.impl.StdSchedulerFactory;

    /**
     * <p>
     * A ServletContextListner that can be used to initialize Quartz.
     * </p>
     *
     * <p>
     * You'll want to add something like this to your WEB-INF/web.xml file:
     *
     * <pre>
     *     &lt;context-param&gt;
     *         &lt;param-name&gt;config-file&lt;/param-name&gt;
     *         &lt;param-value&gt;/some/path/my_quartz.properties&lt;/param-value&gt;
     *     &lt;/context-param&gt;
     *     &lt;context-param&gt;
     *         &lt;param-name&gt;shutdown-on-unload&lt;/param-name&gt;
     *         &lt;param-value&gt;true&lt;/param-value&gt;
     *     &lt;/context-param&gt;
     *     &lt;context-param&gt;
     *         &lt;param-name&gt;start-scheduler-on-load&lt;/param-name&gt;
     *         &lt;param-value&gt;true&lt;/param-value&gt;
     *     &lt;/context-param&gt;
     *     
     *     &lt;listener&gt;
     *         &lt;listener-class&gt;
     *             org.quartz.ee.servlet.QuartzInitializerListener
     *         &lt;/listener-class&gt;
     *     &lt;/listener&gt;
     * </pre>
     *
     * </p>
     * <p>
     * The init parameter 'config-file' can be used to specify the path (and
     * filename) of your Quartz properties file. If you leave out this parameter,
     * the default ("quartz.properties") will be used.
     * </p>
     *
     * <p>
     * The init parameter 'shutdown-on-unload' can be used to specify whether you
     * want scheduler.shutdown() called when the servlet is unloaded (usually when
     * the application server is being shutdown). Possible values are "true" or
     * "false". The default is "true".
     * </p>
     *
     * <p>
     * The init parameter 'start-scheduler-on-load' can be used to specify whether
     * you want the scheduler.start() method called when the servlet is first loaded.
     * If set to false, your application will need to call the start() method before
     * the scheduler begins to run and process jobs. Possible values are "true" or
     * "false". The default is "true", which means the scheduler is started.
     * </p>
     *
     * A StdSchedulerFactory instance is stored into the ServletContext. You can gain access
     * to the factory from a ServletContext instance like this:
     * <br>
     * <pre>
     * StdSchedulerFactory factory = (StdSchedulerFactory) ctx
     *                .getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);</pre>
     * <p>
     * The init parameter 'servlet-context-factory-key' can be used to override the
     * name under which the StdSchedulerFactory is stored into the ServletContext, in 
     * which case you will want to use this name rather than 
     * <code>QuartzInitializerListener.QUARTZ_FACTORY_KEY</code> in the above example.
     * </p>
     *
     * <p>
     * The init parameter 'start-delay-seconds' can be used to specify the amount
     * of time to wait after initializing the scheduler before scheduler.start()
     * is called.
     * </p>
     *
     * Once you have the factory instance, you can retrieve the Scheduler instance by calling
     * <code>getScheduler()</code> on the factory.
     *
     * 
    @author James House
     * 
    @author Chuck Cavaness
     * 
    @author John Petrocik
     
    */

    public class QuartzInitializerListener implements ServletContextListener {

        
    public static final String QUARTZ_FACTORY_KEY = "org.quartz.impl.StdSchedulerFactory.KEY";

        
    private boolean performShutdown = true;

        
    private Scheduler scheduler = null;

        
    /*
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         *
         * Interface.
         *
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         
    */


        
    public void contextInitialized(ServletContextEvent sce) {

            System.out.println(
    "Quartz Initializer Servlet loaded, initializing Scheduler");

            ServletContext servletContext 
    = sce.getServletContext();
            StdSchedulerFactory factory;
            
    try {

                String configFile 
    = servletContext.getInitParameter("config-file");
                String shutdownPref 
    = servletContext.getInitParameter("shutdown-on-unload");

                
    if (shutdownPref != null{
                    performShutdown 
    = Boolean.valueOf(shutdownPref).booleanValue();
                }


                
    // get Properties
                if (configFile != null{
                    factory 
    = new StdSchedulerFactory(configFile);
                }
     else {
                    factory 
    = new StdSchedulerFactory();
                }


                
    // Always want to get the scheduler, even if it isn't starting, 
                
    // to make sure it is both initialized and registered.
                scheduler = factory.getScheduler();

                
    // Should the Scheduler being started now or later
                String startOnLoad = servletContext
                        .getInitParameter(
    "start-scheduler-on-load");

                
    int startDelay = 0;
                String startDelayS 
    = servletContext.getInitParameter("start-delay-seconds");
                
    try {
                    
    if(startDelayS != null && startDelayS.trim().length() > 0)
                        startDelay 
    = Integer.parseInt(startDelayS);
                }
     catch(Exception e) {
                    System.out.println(
    "Cannot parse value of 'start-delay-seconds' to an integer: " + startDelayS + ", defaulting to 5 seconds.");
                    startDelay 
    = 5;
                }


                
    /*
                 * If the "start-scheduler-on-load" init-parameter is not specified,
                 * the scheduler will be started. This is to maintain backwards
                 * compatability.
                 
    */

                
    if (startOnLoad == null || (Boolean.valueOf(startOnLoad).booleanValue())) {
                    
    if(startDelay <= 0{
                        
    // Start now
                        scheduler.start();
                        System.out.println(
    "Scheduler has been started");
                    }

                    
    else {
                        
    // Start delayed
                        scheduler.startDelayed(startDelay);
                        System.out.println(
    "Scheduler will start in " + startDelay + " seconds.");
                    }

                }
     else {
                    System.out.println(
    "Scheduler has not been started. Use scheduler.start()");
                }


                String factoryKey 
    = 
                    servletContext.getInitParameter(
    "servlet-context-factory-key");
                
    if (factoryKey == null{
                    factoryKey 
    = QUARTZ_FACTORY_KEY;
                }


                System.out.println(
    "Storing the Quartz Scheduler Factory in the servlet context at key: "
                        
    + factoryKey);
                servletContext.setAttribute(factoryKey, factory);

            }
     catch (Exception e) {
                System.out.println(
    "Quartz Scheduler failed to initialize: " + e.toString());
                e.printStackTrace();
            }

        }


        
    public void contextDestroyed(ServletContextEvent sce) {

            
    if (!performShutdown) {
                
    return;
            }


            
    try {
                
    if (scheduler != null{
                    scheduler.shutdown();
                }

            }
     catch (Exception e) {
                System.out.println(
    "Quartz Scheduler failed to shutdown cleanly: " + e.toString());
                e.printStackTrace();
            }


            System.out.println(
    "Quartz Scheduler successful shutdown.");
        }



    }

    主站蜘蛛池模板: 亚洲日本在线观看| 亚洲熟妇中文字幕五十中出| 在线观看国产情趣免费视频| 日本免费人成黄页网观看视频 | 国产成人福利免费视频| 69堂人成无码免费视频果冻传媒| 久久精品女人天堂AV免费观看| 精品免费国产一区二区三区| 亚洲精品WWW久久久久久| 久久精品国产精品亚洲精品| 亚洲高清在线视频| 97se亚洲国产综合自在线| 老司机午夜在线视频免费观| 免费精品一区二区三区第35| 69堂人成无码免费视频果冻传媒| 免费一级特黄特色大片在线 | 国产亚洲精aa在线看| 色噜噜狠狠色综合免费视频| 一个人免费视频观看在线www| 国产成人精品免费视频大| 国产伦精品一区二区三区免费下载| 337p日本欧洲亚洲大胆裸体艺术| 亚洲视频在线观看地址| 亚洲av成人片在线观看| 毛片免费在线观看| 成人毛片18女人毛片免费| 亚洲女初尝黑人巨高清| 亚洲人成在线精品| www免费黄色网| **实干一级毛片aa免费| 免费乱码中文字幕网站| 亚洲视频在线免费观看| 亚洲AV成人无码久久WWW| 久久免费视频99| 国产精品深夜福利免费观看| 亚洲精品无码国产| 亚洲人成色在线观看| 男人都懂www深夜免费网站| 在线看片无码永久免费aⅴ | 亚洲ⅴ国产v天堂a无码二区| 亚洲AV无码一区二区一二区|