Deep understanding of Tomcat

Source: Internet
Author: User
Brief Introduction

Tomcat is a Web server that runs the JSP and Servlet and communicates with the client (usually the browser) using HTTP. constitute

The following figure is the Tomcat architecture, as you can see: The core content is the connector and container components.

There may be multiple service,service in one server server that can be temporarily understood as "services." The server is responsible for managing the life cycle of the service to allow access to the outside world.

Service will connector and container linked together, similar to "a paper marriage", will be a couple together to form a family.

Let's take a look at the core content section 1, Connector

While learning the basics of the Java Web, the Web container creates a request and response object after the HTTP request is passed from the browser. In Tomcat, the connector component is responsible for the creation of the work.

Connector connectors can have one or more, by default, two HTTP protocols and AJP protocols are opened.

2, Container

Let's take a look at the detailed structure chart of container:

The container container has four child containers: Engine, Host, context, and wrapper, which are parent-child inclusion relationships. 1), Engine 2), host (virtual host) 3), Context (Web application contexts to which they belong) 4, wrapper (for each specific servlet, it can be said that he is the most direct and servlet dealings.) )

The

can look at Tomcat's server.xml files to get an insight into the relationships between the components.

<?xml version= "1.0" encoding= "UTF-8"?> <!--server--> <server port= "8005" shutdown= "Shutdown" > < Service name= "Catalina" > <!--A "Connector" represents A endpoint by which requests are received and Responses are returned. Documentation At:java HTTP Connector:/docs/config/http.html (Blocking & non-blocking) Java AJP C Onnector:/docs/config/ajp.html APR (HTTP/AJP) Connector:/docs/apr.html Define a Non-ssl http/1.1 ctor on port 8080--> <connector uriencoding= "GB18030" connectiontimeout= "20000" port= "8080" protocol= "HTTP/" 1.1 "redirectport=" 8443 "/> <!--A" Connector "using the shared thread pool--> <!--<connector E
               Xecutor= "Tomcatthreadpool" port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/>--> <!--Define a SSL http/1.1 Connector on port 8443 this Connec Tor Uses the JSSE configuration, when using APR, the connector should is using the OpenSSL style configuration Described in the APR documentation--> <!--<connector port= "8443" protocol= "http/1.1" sslenabled= "tr 
    UE "maxthreads=" scheme= "https" secure= "true" Clientauth= "false" sslprotocol= "TLS"/> --> <!--Define a AJP 1.3 Connector on port 8009 "--> <connector port=" 8009 "protocol=" ajp/1.3 " redirectport= "8443"/> <!--a Engine represents the entry point (within Catalina) that processes ever  Y request. The Engine implementation for Tomcat stand alone analyzes the HTTP headers with the request, and included
         them on to the appropriate host (virtual host). Documentation at/docs/config/engine.html--> <engine defaulthost= "localhost" name= "Catalina" >  

Design Ideas 1 Responsibility Chain mode

When designing the container, we can see clearly that the Engine, host, context and wrapper are connected into a chain. When the request arrives, it is passed through the chain and finally arrives at the child container that handles the request. The example of the big talk is "leave approval", the staff leave process is a layer of a layer, if the manager can approve, no longer go on the process. If the manager has no authority to approve, go to a level of general manager transmission, the general manager can be approved for approval, can not be approved, the request will continue to go on until someone has handled or requested to be revoked.

Multiple objects have the opportunity to process requests, and the coupling between sending and processing requests weakens. Object into a chain, passing the request along the chain until an object handles it. 2) Command mode

Command mode is used when designing connector and container relationships.

Tomcat can have multiple connector, multiple connector, and a container to form a service. Connector is the requester, and container is the person who accepts the order and executes it. Similar to the big talk design pattern, the customer orders the meal to bake a string example.

The request is encapsulated into an object, we can encapsulate various requests with the parameter, and make the request queue to complete the function of the prompt cancellation. 3) Observer mode

This pattern is more commonly used, meaning is needless to say, often used to implement "asynchronous processing." There are many places in Tomcat used in this mode, such as: the creation of servlet strength, session management, lifecycle and so on.

The observer pattern, also known as the event listener mechanism, is also called the Publish-subscribe model. Think of anything. JMS implements the PUB-SUB message model for asynchronous message processing, as well as the channel registration of multiple selector in a message in NiO and so on.

The example of big talk is "boss back, I don't know".

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.