码迷,mamicode.com
首页 > 其他好文 > 详细

[tomcat] tomcat简析(一)

时间:2017-09-21 18:06:30      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:response   server   context   一个   container   相关   eth   分享   getc   

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

    }

  

 

[tomcat] tomcat简析(一)

标签:response   server   context   一个   container   相关   eth   分享   getc   

原文地址:http://www.cnblogs.com/qunan/p/7569315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!