• [tomcat] tomcat简析(一)


    1.Tomcat的顶层结构

       Tomcat中最顶层的容器叫Server,代表整个服务器,Server中包含至少一个Service,用于 具体提供服务。

       Service主要包含两部分:Connector和Container。Connector用于处理连接相关 的事情,并提供Socket与request、response的转换,Container用于封装和管理Servlet,以及具 体处理request请求。一个Tomcat中只有一个Server, —个Server可以包含多个Service,一个 Service只有一个Container,但可以有多个Connectors (因为一个服务可以有多个连接,如同时 提供http和https连接,也可以提供相同协议不同端门的连接),结构图如图

      2. Bootstrap 的启动过程

         

    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);
            }
    
        }
    

      

  • 相关阅读:
    分布式系统(Distributed System)资料
    (转)hive基本操作
    c# 如何通过反射 获取设置属性值、
    安卓webview下使用zepto的swipe失效
    js获取本月、三个月、今年的日期插件dateHelp
    jquery获取form表单内容以及绑定数据到form表单
    JQuery阻止事件冒泡
    javascript-Cookie的应用
    chrome浏览器调试
    JavaScript设计模式之命令模式
  • 原文地址:https://www.cnblogs.com/qunan/p/7569315.html
Copyright © 2020-2023  润新知