zoukankan      html  css  js  c++  java
  • tomcat源码阅读_代码篇1

    首先读Bootstrap类,该类在how Tomcat works里有比较详细的介绍,结合书和代码看应该没有问题。接下来看Catalina类,主要主要该类中的start()方法:

        /**
         * Start a new server instance.
         */
        public void start() {

            if (server == null) {
                load();
            }

            long t1 = System.nanoTime();
           
            // Start the new server
            if (server instanceof Lifecycle) {
                try {
                    ((Lifecycle) server).start();
                } catch (LifecycleException e) {
                    log.error("Catalina.start: ", e);
                }
            }

            long t2 = System.nanoTime();
            if(log.isInfoEnabled())
                log.info("Server startup in " + ((t2 - t1) / 1000000) + " ms");

            try {
                // Register shutdown hook
                if (useShutdownHook) {
                    if (shutdownHook == null) {
                        shutdownHook = new CatalinaShutdownHook();
                    }
                    Runtime.getRuntime().addShutdownHook(shutdownHook);
                }
            } catch (Throwable t) {
                // This will fail on JDK 1.2. Ignoring, as Tomcat can run
                // fine without the shutdown hook.
            }

            if (await) {
                await();
                stop();
            }

        }

    下面是使用的时候的load方法
        /**
         * Start a new server instance.
         */
        public void load() {

            long t1 = System.nanoTime();

            initDirs();

            // Before digester - it may be needed

            initNaming();

            // Create and execute our Digester初始化组件根据XML文件在这里完成
            Digester digester = createStartDigester();

            InputSource inputSource = null;
            InputStream inputStream = null;
            File file = null;
            try {
                file = configFile();
                inputStream = new FileInputStream(file);
                inputSource = new InputSource("file://" + file.getAbsolutePath());
            } catch (Exception e) {
                ;
            }
            if (inputStream == null) {
                try {
                    inputStream = getClass().getClassLoader()
                        .getResourceAsStream(getConfigFile());
                    inputSource = new InputSource
                        (getClass().getClassLoader()
                         .getResource(getConfigFile()).toString());
                } catch (Exception e) {
                    ;
                }
            }

            // This should be included in catalina.jar
            // Alternative: don't bother with xml, just create it manually.
            if( inputStream==null ) {
                try {
                    inputStream = getClass().getClassLoader()
                    .getResourceAsStream("server-embed.xml");
                    inputSource = new InputSource
                    (getClass().getClassLoader()
                            .getResource("server-embed.xml").toString());
                } catch (Exception e) {
                    ;
                }
            }
           

            if ((inputStream == null) && (file != null)) {
                log.warn("Can't load server.xml from " + file.getAbsolutePath());
                return;
            }

            try {
                inputSource.setByteStream(inputStream);
                digester.push(this);
                digester.parse(inputSource);
                inputStream.close();
            } catch (Exception e) {
                log.warn("Catalina.start using "
                                   + getConfigFile() + ": " , e);
                return;
            }

            // Stream redirection
            initStreams();

            // Start the new server
            if (server instanceof Lifecycle) {
                try {
                    server.initialize();
                } catch (LifecycleException e) {
                    log.error("Catalina.start", e);
                }
            }

            long t2 = System.nanoTime();
            if(log.isInfoEnabled())
                log.info("Initialization processed in " + ((t2 - t1) / 1000000) + " ms");

        }

  • 相关阅读:
    js右击事件
    css中的特殊居中
    js实现轮播图
    css画三角形
    Elasticsearch-5.5.0安装head插件
    Elasticsearch报错:NodeDisconnectedException[[][IP:9300][cluster:monitor/nodes/liveness] disc
    mybatis foreach多次遍历问题
    Java使用File.separator解决Win和Linux的路径问题
    WebStorm 代码提示快捷键
    springmvc 前台传日期(字符串) 后台用date接收封装失败(请求400)
  • 原文地址:https://www.cnblogs.com/macula7/p/1960493.html
Copyright © 2011-2022 走看看