• 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
  • 相关阅读:
    互动教程,让你5分钟掌握 Flexbox 布局模式
    Fixed Responsive Nav – 响应式的单页网站导航插件
    创意无限!一组网页边栏过渡动画【附源码下载】
    12款界面精美的 HTML5 & CSS3 网站模板
    Twproject Gantt – 开源的 JavaScript 甘特图组件
    真是好东西!一组动感的页面加载动画效果
    Method Draw – 很好用的 SVG 在线编辑器
    CSS Vocabulary – CSS 词汇表,你都掌握了吗?
    前端精选文摘:BFC 神奇背后的原理
    Vis.js – 基于浏览器的动态 JavaScript 可视化库
  • 原文地址:https://www.cnblogs.com/davidwang456/p/3253523.html
Copyright © 2020-2023  润新知