zoukankan      html  css  js  c++  java
  • tomcat 容器生命周期lifecycle

    1.复习java的事件机制

    java事件机制包括三个部分:事件、事件监听器、事件源。

    事件:一般继承自java.util.EventObject类,封装了事件源对象及跟事件相关的信息。

    事件监听器:实现java.util.EventListener接口,注册在事件源上,当事件源的属性或状态改变时,取得相应的监听器调用其内部的回调方法。

    事件源:事件发生的地方,由于事件源的某项属性或状态发生了改变(比如BUTTON被单击、TEXTBOX的值发生改变等等)导致某项事件发生。

    2. tomcat的lifecycle

     事件定义

    public final class LifecycleEvent extends EventObject {
     
        private static final long serialVersionUID = 1L;
     
     
        // ----------------------------------------------------------- Constructors
     
        /**
         * Construct a new LifecycleEvent with the specified parameters.
         *
         * @param lifecycle Component on which this event occurred
         * @param type Event type (required)
         * @param data Event data (if any)
         */
        public LifecycleEvent(Lifecycle lifecycle, String type, Object data) {
     
            super(lifecycle);
            this.type = type;
            this.data = data;
        }
    }

    事件监听器

    /**
     * Interface defining a listener for significant events (including "component
     * start" and "component stop" generated by a component that implements the
     * Lifecycle interface. The listener will be fired after the associated state
     * change has taken place.
     *
     * @author Craig R. McClanahan
     * @version $Id: LifecycleListener.java 1200160 2011-11-10 05:35:13Z kkolinko $
     */
     
    public interface LifecycleListener {
     
     
        /**
         * Acknowledge the occurrence of the specified event.
         *
         * @param event LifecycleEvent that has occurred
         */
        public void lifecycleEvent(LifecycleEvent event);
     
     
    }
     *            start()
     *  -----------------------------
     *  |                           |
     *  | init()                    |
     * NEW ->-- INITIALIZING        |
     * | |           |              |     ------------------<-----------------------
     * | |           |auto          |     |                                        |
     * | |          |/    start() |/   |/     auto          auto         stop() |
     * | |      INITIALIZED -->-- STARTING_PREP -->- STARTING -->- STARTED -->---  |
     * | |         |                                                  |         |  |
     * | |         |                                                  |         |  |
     * | |         |                                                  |         |  |
     * | |destroy()|                                                  |         |  |
     * | -->-----<--       auto                    auto               |         |  |
     * |     |       ---------<----- MUST_STOP ---------------------<--         |  |
     * |     |       |                                                          |  |
     * |    |/      ---------------------------<--------------------------------  ^
     * |     |       |                                                             |
     * |     |      |/            auto                 auto              start()  |
     * |     |  STOPPING_PREP ------>----- STOPPING ------>----- STOPPED ---->------
     * |     |                                ^                  |  |  ^
     * |     |               stop()           |                  |  |  |
     * |     |       --------------------------                  |  |  |
     * |     |       |                                  auto     |  |  |
     * |     |       |                  MUST_DESTROY------<-------  |  |
     * |     |       |                    |                         |  |
     * |     |       |                    |auto                     |  |
     * |     |       |    destroy()      |/              destroy() |  |
     * |     |    FAILED ---->------ DESTROYING ---<-----------------  |
     * |     |                        ^     |                          |
     * |     |     destroy()          |     |auto                      |
     * |     -------->-----------------    |/                         |
     * |                                 DESTROYED                     |
     * |                                                               |
     * |                            stop()                             |
     * --->------------------------------>------------------------------

    public interface Lifecycle

    3. lifecycle在tomcat中的使用。

    public interface Server extends Lifecycle
     
    public interface Service extends Lifecycle 
     
    public interface Container extends Lifecycle
  • 相关阅读:
    初学Django
    Git的初始化配置和基本命令的使用
    python读取和写入excel里面的数据(附int变float解决方法)
    启动Django报错ModuleNotFoundError: No module named 'pytz'
    pytest之参数化
    解决pytest运行时报错ModuleNotFoundError
    专业程序员必知的技巧:敲打代码
    开源项目文档应规避的13处“硬伤”
    [置顶] 理解Linux系统负荷
    六大开源监测工具 你用过哪个?
  • 原文地址:https://www.cnblogs.com/davidwang456/p/3253523.html
Copyright © 2011-2022 走看看