zoukankan      html  css  js  c++  java
  • Tomcat9源码分析:BootStrap

    概览

    BootStrap源码所在的位置是:org.apache.catalina.startup.Bootstrap

    这个类是Tomcat项目的启动类,也就是main函数所在的地方,起始tomcat就是一个简单的Java项目,还是最简单的那种。

    static {
        // 静态方法块, 做一些启动前的准备工作
    }
    
    /**
     * 启动Catalina后台.
     */
    public void start();
    
    /**
     * 停止Catalina后台.
     */
    public void stop();
    
    /**
     * 停止standalone server.
     */
    public void stopServer;
    
    /**
     * 是否阻塞Catalina的后台
     */
    public void setAwait(boolean await);
    
    public boolean getAwait;
    
    /**
     * 销毁Catalina后台.
     */
    public void destroy();
    
    /**
     * 程序入口
     */
    public static void main(String args[]);

    BootStrap类的作用也挺简单的,就是在main方法中调用上面的那几个start,await,stop,destroy方法。

    BootStrap的静态代码块分析

    static {
        String userDir = System.getProperty("user.dir");
        // 这个值在虚拟机选项中进行设置的 -Dcatalina.home=D:my_projectcatalina-home
        String home = System.getProperty(Globals.CATALINA_HOME_PROP);
        File homeFile = null;
    
        if (home != null) {
            File f = new File(home);       // 如果catalina.home这个属性不为空
            try {
                homeFile = f.getCanonicalFile();    // 返回此抽象路径名的规范形式
            } catch (IOException ioe) {
                homeFile = f.getAbsoluteFile();
            }
        }
    
        if (homeFile == null) {
            // First fall-back. See if current directory is a bin directory
            // in a normal Tomcat install
            File bootstrapJar = new File(userDir, "bootstrap.jar");
    
            if (bootstrapJar.exists()) {
                File f = new File(userDir, "..");
                try {
                    homeFile = f.getCanonicalFile();
                } catch (IOException ioe) {
                    homeFile = f.getAbsoluteFile();
                }
            }
        }
    
        if (homeFile == null) {
            // Second fall-back. Use current directory
            File f = new File(userDir);
            try {
                homeFile = f.getCanonicalFile();
            } catch (IOException ioe) {
                homeFile = f.getAbsoluteFile();
            }
        }
    
        catalinaHomeFile = homeFile;
        System.setProperty(Globals.CATALINA_HOME_PROP, catalinaHomeFile.getPath());
    
        // Then base
        String base = System.getProperty(Globals.CATALINA_BASE_PROP);
        if (base == null) {
            catalinaBaseFile = catalinaHomeFile;
        } else {
            File baseFile = new File(base);
            try {
                baseFile = baseFile.getCanonicalFile();
            } catch (IOException ioe) {
                baseFile = baseFile.getAbsoluteFile();
            }
            catalinaBaseFile = baseFile;
        }
        System.setProperty(Globals.CATALINA_BASE_PROP, catalinaBaseFile.getPath());
    }

    起始这段static代码做的事情很简单,就是确定catalina.home的目录和catalina.base的目录,这里有两个东西暂时留着:

    1. 这一static的时序图

    2. catalina.base和catalina.home的区别

    image

    不好意思,没有分析源码,直接跑到这儿来了,兴不兴奋,激不激动:

    image

  • 相关阅读:
    IPC(进程间通信)
    进程和线程是什么
    虚拟内存
    寄存器是什么?内存、寄存器和存储器的区别
    计算机资源 —硬件资源分配
    如何将一个网页中自己想要的数据导入到Excel表格中
    Putty的安装和使用
    SQL中的ON DUPLICATE KEY UPDATE使用详解
    sql:主键(primary key)和唯一索引(unique index)区别
    直接扩频通信(上)理论基础
  • 原文地址:https://www.cnblogs.com/tuhooo/p/7879949.html
Copyright © 2011-2022 走看看