zoukankan      html  css  js  c++  java
  • tomcat的启动类

    org.apache.catalina.startup.Bootstrap   的main方法-->这个方法是整个tomcat的入口。

    1、main方法

        public static void main(String args[]) {
    
            if (daemon == null) {
                // Don't set daemon until init() has completed
                Bootstrap bootstrap = new Bootstrap();
                try {
                    bootstrap.init();
                } catch (Throwable t) {
                    handleThrowable(t);
                    t.printStackTrace();
                    return;
                }
                daemon = bootstrap;
            } else {
                // When running as a service the call to stop will be on a new
                // thread so make sure the correct class loader is used to prevent
                // a range of class not found exceptions.
                Thread.currentThread().setContextClassLoader(daemon.catalinaLoader);
            }
    
            try {
                String command = "start";
                if (args.length > 0) {
                    command = args[args.length - 1];
                }
    
                if (command.equals("startd")) {
                    args[args.length - 1] = "start";
                    daemon.load(args);
                    daemon.start();
                } else if (command.equals("stopd")) {
                    args[args.length - 1] = "stop";
                    daemon.stop();
                } else if (command.equals("start")) {
                    daemon.setAwait(true);
                    daemon.load(args);
                    daemon.start();
                } else if (command.equals("stop")) {
                    daemon.stopServer(args);
                } else if (command.equals("configtest")) {
                    daemon.load(args);
                    if (null==daemon.getServer()) {
                        System.exit(1);
                    }
                    System.exit(0);
                } else {
                    log.warn("Bootstrap: command "" + command + "" does not exist.");
                }
            } catch (Throwable t) {
                // Unwrap the Exception for clearer error reporting
                if (t instanceof InvocationTargetException &&
                        t.getCause() != null) {
                    t = t.getCause();
                }
                handleThrowable(t);
                t.printStackTrace();
                System.exit(1);
            }
    
        }

    2、tomcat的类加载器

     3、java的namespace

       tomcat的bootstrap和catalina之间的调用为什么都是通过反射呢,就是因为这两个类不是通过同一个类加载器加载的。

     参考文献:

    java类加载器的实现:https://www.cnblogs.com/wskwbog/p/10827102.html

    java的启动过程源码解析:https://www.cnblogs.com/z941030/p/8524882.html

  • 相关阅读:
    python之函数用法id(),了解即可
    python之函数用法locals()
    python之函数用法vars()
    python之函数用法execfile()
    python之函数用法isinstance()
    python之函数用法any()
    python之函数用法iter()
    python之函数用法file()
    python之函数用法bin()
    python之函数用法basestring
  • 原文地址:https://www.cnblogs.com/erdanyang/p/11803713.html
Copyright © 2011-2022 走看看