zoukankan      html  css  js  c++  java
  • tomcat源码分析 StandardContext startInternal 过程

    1、Send j2ee.state.starting notification 

    if (this.getObjectName() != null) {
                Notification notification = new Notification("j2ee.state.starting",
                        this.getObjectName(), sequenceNumber.getAndIncrement());
                broadcaster.sendNotification(notification);
            }

    2、实例化webappResources

        有两个实现类,new FileDirContext(), new WARDirContext()

        在我本机环境上是new FileDirContext()

       

    3、webappResources 属性做一些初始设置,并生成ProxyDirContext对象。

        在resourcesStart()方法中完成。

    4、WebappLoader实例化

       

    if (getLoader() == null) {
                WebappLoader webappLoader = new WebappLoader(getParentClassLoader());
                webappLoader.setDelegate(getDelegate());
                setLoader(webappLoader);
            }

    5、CharsetMapper实例化

       

    @Override
        public CharsetMapper getCharsetMapper() {
    
            // Create a mapper the first time it is requested
            if (this.charsetMapper == null) {
                try {
                    Class<?> clazz = Class.forName(charsetMapperClass);
                    this.charsetMapper = (CharsetMapper) clazz.newInstance();
                } catch (Throwable t) {
                    ExceptionUtils.handleThrowable(t);
                    this.charsetMapper = new CharsetMapper();
                }
            }
    
            return (this.charsetMapper);
    
        }

    6、work directory 设置。

       在我本机环境上是:workCatalinalocalhost\_

    7、Validate required extensions

    try {
                dependencyCheck = ExtensionValidator.validateApplication
                    (getResources(), this);
            } catch (IOException ioe) {
                log.error("Error in dependencyCheck", ioe);
                dependencyCheck = false;
            }

    8、NamingContextListener注册

    9、之前的WebappLoad 启动。

    if ((loader != null) && (loader instanceof Lifecycle))
                        ((Lifecycle) loader).start();

    10、resources 启动。

    11、触发CONFIGURE_START_EVENT事件。

          

    fireLifecycleEvent(Lifecycle.CONFIGURE_START_EVENT, null);

      将触发ContextConfig、TldConfig等重要监听器。

    12、StandardPipeline启动。

    ((Lifecycle) pipeline).start();

    13、session管理器实例化,如无特别设置,实现类应该是new StandardManager()

    14、InstanceManager实例化,并设置

    15、servletContext 上下文参数设置

    16、触发ServletContainerInitializer的onStartUp方法

    17、监听器启动

    if (!listenerStart()) {
                        log.error( "Error listenerStart");
                        ok = false;
                    }

    18、session管理器启动。

    if ((manager != null) && (manager instanceof Lifecycle)) {
                        ((Lifecycle) getManager()).start();
                    }

    19、启动后台线程:ContainerBackgroundProcessor

    20、过滤器启动。

    if (!filterStart()) {
                        log.error("Error filterStart");
                        ok = false;
                    }

    21、启动设置load on startup元素的servlet

    loadOnStartup(findChildren());

    22、关闭打开的jar文件。

    if (getLoader() instanceof WebappLoader) {
                ((WebappLoader) getLoader()).closeJARs(true);
            }

    23、设置成功启动状态。

  • 相关阅读:
    为什么 JVM 不用 JIT 全程编译?
    JVM Internals
    JIT与JVM的三种执行模式:解释模式、编译模式、混合模式
    Dart编译技术与平台
    Dart 库预览
    使用VSCode开发Flutter
    环境变量
    使用Homebrew管理你的mac开发包
    brew 又叫Homebrew,是Mac OSX上的软件包管理工具
    使用async/await消除callback hell
  • 原文地址:https://www.cnblogs.com/knockon/p/3339810.html
Copyright © 2011-2022 走看看