Tomcat Architecture 官方文档

转载自:Tomcat Architecture 官方文档

Architecture Overview

Server

In the Tomcat world, a Server represents the whole container. Tomcat provides a default implementation of the Server interface which is rarely customized by users.


Service

A Service is an intermediate component which lives inside a Server and ties one or more Connectors to exactly one Engine. The Service element is rarely customized by users, as the default implementation is simple and sufficient: Service interface.


Engine

An Engine represents request processing pipeline for a specific Service. As a Service may have multiple Connectors, the Engine receives and processes all requests from these connectors, handing the response back to the appropriate connector for transmission to the client. The Engine interface may be implemented to supply custom Engines, though this is uncommon.


Note that the Engine may be used for Tomcat server clustering via the jvmRoute parameter. Read the Clustering documentation for more information.


Host

A Host is an association of a network name, e.g. www.yourcompany.com, to the Tomcat server. An Engine may contain multiple hosts, and the Host element also supports network aliases such as yourcompany.com and abc.yourcompany.com. Users rarely create custom Hosts because the StandardHost implementation provides significant additional functionality.


Connector

A Connector handles communications with the client. There are multiple connectors available with Tomcat. These include the HTTP connector which is used for most HTTP traffic, especially when running Tomcat as a standalone server, and the AJP connector which implements the AJP protocol used when connecting Tomcat to a web server such as Apache HTTPD server. Creating a customized connector is a significant effort.


Context

A Context represents a web application. A Host may contain multiple contexts, each with a unique path. The Context interface may be implemented to create custom Contexts, but this is rarely the case because the StandardContext provides significant additional functionality.


Comments

Tomcat is designed to be a fast and efficient implementation of the Servlet Specification. Tomcat came about as the reference implementation of this specification, and has remained rigorous in adhering to the specification. At the same time, significant attention has been paid to Tomcat's performance and it is now on par with other servlet containers, including commercial ones.


In recent releases of Tomcat, mostly starting with Tomcat 5, we have begun efforts to make more aspects of Tomcat manageable via JMX. In addition, the Manager and Admin webapps have been greatly enhanced and improved. Manageability is a primary area of concern for us as the product matures and the specification becomes more stable.


=========================

Tomcat Architecture 官方文档_第1张图片

结合Tomcat部署war包过程中的组件实例化过程 做一些内容补充:

  1. Host组件代表请求的域名。在匹配请求先根据请求的域名找到相应的Host,比如名为localhost的Host。
  2. Context也称为servletContext,一个Context代表一个web应用程序(war包)。一个tomcat 部署多个web 项目,tomcat启动即是一个javaw.exe进程,然后为每个Web应用程序创建一个单独的部署线程,然后在该线程中创建相应的Context组件,并在Context.startInternal()中创建相应的WebApp类加载器。
  3. 一个war包中的filter不可能过滤另外一个war包的页面请求。即一个war包中的filter只能对本war包有效。
  4. 先解析Server.xml,再解析web应用程序的web.xml。

Tomcat部署war包过程中的组件实例化过程为:

解析Server.xml,创建各Tomcat组件 :server、service、Connector、Engine。

1、初始化各Tomcat组件。

2、启动各Tomcat组件。

启动Engine组件的详细过程如下:

  • 每个Host创建一个部署线程。Host在部署线程中调用HostConfig.deployApps()部署Web应用程序。
  • 为每个Web应用程序创建一个单独的部署线程,然后在该线程中创建相应的Context组件,并在Context.startInternal()中创建相应的WebApp类加载器。
  • Context组件开始解析web.xml。在ContextConfig.webConfig()中解析web.xml部署描述文件,在ContextConfig.configureContext(WebXml webxml)根据解析web.xml的信息创建封装各种应用元素,如Filter、Servlet、Session等等,其中Servlet被封装成Wrapper,加入到相应的Context组件中。

你可能感兴趣的:(tomcat,&,servlet)