In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of the overall structure of Tomcat, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Tomcat is well known as a web container, and it has been with me throughout my programming career since I first started learning Java until now. The essence of Tomcat is a Servlet container. What a Servlet can do is process the requested resources and populate the client with response objects.
Tomcat is responsible for loading the Servlet class we wrote, calling the init () method of Servlet, creating a servletRequest and an instance of servletResponse for a request request, calling the service () method of the servlet, passing in servletRequest and servletResponse as parameters, and calling destroy () and uninstalling it when the servlet is closed. Next, let's briefly introduce the overall structure of Tomcat.
The overall structure of Tomcat
As shown in the figure, the two main components of Tomcat are connector and container. Multiple connector and a container form a service,service to provide services, while the life cycle of service is controlled by server. Server belongs to the top-level abstraction.
Connectors (connector) are used to handle things related to network connections, such as socket connections, request encapsulation, connection thread pooling and so on. The container (container) mainly handles requests accepted by connector. Service just wraps an extra layer around Connector and Container, assembles them together and provides services to the outside world. A Service can set up multiple Connector, but there can only be one Container container. The life cycle of all components is managed uniformly using the lifecycle interface, which includes the init,start,stop,destory method.
The original connector (connector) can only be set to BIO mode, but now the default connection mode of the high version of Tomcat is NIO, which greatly increases the concurrency of requests.
There are four forms of container in tomcat, with engine,host,context,wrapper from top to bottom. A wrapper corresponds to an servlet, an context corresponds to an application, a host corresponds to a site, engine is the engine, and there is only one container. All launches between containers are started using the
Tomcat container model
After a brief introduction to the whole structure of Tomcat, let's deepen our understanding by Tomcat the processing flow of a request. Suppose the request is: http://localhost:8080/test/index.jsp, then the processing flow of Tomcat is
1. The request is sent to port 8080 and obtained by connector.
2.connector hands the request to the engine of his service and waits for the engine to respond.
3.engine obtains the request address, which matches the virtual host host
The 4.engine matches to a host named localhost, and the host gets the request / test/index.jsp that matches the context owned by the host
5.host matches to the context with the path / test. If it fails to match, it will be processed by the context named "empty".
6. The context gets the request / index.jsp and looks for the corresponding servlet in the mapping file
7.context matches to the servlet with the pattern * .jsp, and finds the corresponding JspServlet class (Jsp will eventually be converted to Servlet)
8. Construct htttpservletrequest and httpServletResponse objects and call doGet or doPost of JspServlet as parameters
9.context returns response to host
10.host returns response to engine
11.engine returns response to connector
12.connector returns the response to the user's browser, and the request ends
Thank you for reading this article carefully. I hope the article "sample Analysis of the overall structure of Tomcat" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.