Tomcat Source Analysis (i) speaking from the Tomcat architecture

Source: Internet
Author: User

First of alldowloadSource and import intoEclipseIn,The level of code code after the import is as shown. Let's take a quick look.TomcatThe structure of the source code.javaxThis package is mainly aboutjava EENormative, such asServletWait, it's not our main analysis. Need to analyze aOrg.apacheSub-Package under,whichCatalinais important in thatTomcatThe boot is in the package under theStartupUnder the bag,

catalina also defines tomcat container (Server,service,engine,host,context) The interface. The implementation of the interface is also under the package, Org.apache.catalina.core . Includes tomcat piping mechanism Span style= "font-family:"liberation serif", Serif "> each tomcat most core East one package.

Let's take a look at connector, see the name, this package is responsible for processing the request, the final request will go into the package under the coyoteadapter service method to handle.

Let's continue to sayCoyoteThis bag, this bag is slightly lower, it willSocketThe data that is transferred is packaged and then transferred to the implementation toAdapterInterface class, where the implementation is also implemented by theCatalinaUnder theCoyoteadapterTo achieve, this package is mainly forTCP/IPTransmission to the East data processing, which is implemented by two ways, one is to useAJPProtocol, the other is the use ofhttpprotocol, simply put, this package is theTCP/IP (PassSocket)Layer to the object to be wrapped and packaged asAJPOrhttpObject, and then forwards it to theCatalinaUnder theconnectorIn the process.

Next we're going to simplyTomcatThis package does the analysis, the core of which isutilPackage, whereThreadsUnder the bag isTomcatmade its own extension to the thread pool.(InExecutorFramework based on)。 The most central part of this isNetPackage, this package is really come out of the network, that is, the request will come first to this package(Note: It is still inTCP/IPAnd it didn't come to the level.httpLevel),whichJioendpointis also the core of our analysis, the class is the actual processingSocketThe request, where the request is accepted and the request is forwarded to the worker thread to be processed is implemented in this package.


After talking about the Tomcat Code Package Organization, we continue to look at the Tomcat architecture diagram, which is an architectural diagram I've searched for from the internet, which basically gives a complete picture of its architecture.


Let's start with a detailed explanation.Tomcatof the various structures. In this architecture diagram, we seeTomcatContainer body, the largest container of which isServer,ServerUnder contains1ToNAServiceContainerServiceThe container also contains1ToNAEngineContainerEngineThe container below contains1ToNAHostContainerHostThat corresponds to our domain name), the same, HostThe container contains1ToNAContextContainerContextWhich is our usualJavawebapplication). In the actual build environment, we usually only have oneServerContainer, aServiceContainer, aEnginecontainer, but often there are multipleHostcontainers, multipleContextContainers (often also aHostUnder Only oneContext), especially in distributed environments, are often multipleHostContainer.Here's a special note .Connector,connectoris inServiceAmong the containers, TomcatThe default configuration is twoConnector,aConnectoris responsible for handlinghttpprotocol, anotherConnectoris responsible for the processingTomcatan agreement of its ownAJP,we will follow up onhttpof the AgreementConnectoras a detailed elaboration.



any developer who has used Tomcat must also have a certain understanding of the server.xml files in the Conf folder under Tomcat . The server.xml is roughly as follows. whichServer.xmlthe largest parent node isServer, theServerits interface specification is determined by the Org.apache.catalina. Server This interface definition , the implementation of which is implemented by Org.apache.catalina.core.StandardServer , in the subsequent article we will be specific elaboration. Similarly,The Engine,Host, andcontext containers also have their specific interface specifications under the Org.apache.catalina package, and their implementation is Org.apache.catalina.core under this bag.

In the next section, we will elaborate on Tomcat 's parent-child containers.

Tomcat Source Analysis (i) speaking from the Tomcat architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.