Tomcat

TOMCAT源码分析-事件与监听

2018-11-14  本文已影响42人  晴天哥_王志

开篇

  作为Tomcat生命周期的补充,解释下事件的触发。

源码部分

public abstract class LifecycleBase implements Lifecycle {

    private final List<LifecycleListener> lifecycleListeners = 
                                   new CopyOnWriteArrayList<>();

    public void addLifecycleListener(LifecycleListener listener) {
        lifecycleListeners.add(listener);
    }

    protected void fireLifecycleEvent(String type, Object data) {
        LifecycleEvent event = new LifecycleEvent(this, type, data);
        for (LifecycleListener listener : lifecycleListeners) {
            listener.lifecycleEvent(event);
        }
    }

}

事件的触发机制

说明:



说明:

上一篇下一篇

猜你喜欢

热点阅读