Master Tomcat’s Architecture: From Server to Container Explained
This article breaks down Tomcat’s modular architecture, detailing the relationships and functions of Server, Service, Connector, Container, Engine, Host, Context, and Wrapper, and explains how the Pipeline‑Valve mechanism processes requests from start to finish.
1. Tomcat Top-Level Architecture
Tomcat is highly modular; the top‑level container is Server , which can contain one or more Service instances. Each Service includes a Connector and a single Container . The Server controls the lifecycle of the entire Tomcat instance.
2. Tomcat Top-Level Summary
Key points:
Server, Service, Connector, and Container relationships and main functions.
Overall request processing flow within Tomcat.
Concepts of Engine, Host, Context, and Wrapper.
How Container handles requests.
Design patterns used in Tomcat.
3. Relationship Between Connector and Container
A request first reaches a Service, then the Service hands it to a Connector, which wraps the request into Request and Response objects. These objects are passed to the Container for processing, after which the response travels back through the Connector to the client.
Connectors use sockets for network communication and implement both TCP/IP and HTTP protocols.
4. Connector Architecture Analysis
Connectors rely on a ProtocolHandler . Different handlers (e.g., Http11Protocol , Http11NioProtocol ) correspond to different connection types. A ProtocolHandler consists of three components:
Endpoint : manages low‑level socket connections (TCP/IP).
Processor : converts socket data into HTTP Request objects.
Adapter : forwards the request to the Container for servlet processing.
5. Container Architecture Analysis
The Container manages servlets and processes requests. It contains four sub‑containers, illustrated in the diagram below.
Engine : manages multiple virtual hosts.
Host : represents a virtual host (a site).
Context : corresponds to a web application (its WEB-INF and web.xml).
Wrapper : wraps an individual servlet.
In a default Tomcat installation, each subdirectory under webapps is a Context; the ROOT directory is the default application for its Host.
6. How Container Processes Requests
Container processing uses a Pipeline‑Valve chain, an implementation of the Chain‑of‑Responsibility pattern. Each Pipeline has a non‑removable BaseValve that invokes the next lower‑level container’s pipeline.
The processing steps are:
The Connector receives a request and triggers the top‑level Engine pipeline.
EngineValve(s) execute, then invoke the Host pipeline, which runs HostValve(s).
HostValve(s) invoke the Context pipeline, which runs ContextValve(s), finally reaching the Wrapper pipeline.
StandardWrapperValve creates a FilterChain, executes configured Filters, and calls the servlet’s service method.
After all valves finish, the response is handed back to the Connector, which sends it to the client via socket.
7. Summary
Understanding Tomcat’s layered architecture—Server, Service, Connector, Container, Engine, Host, Context, and Wrapper—along with the Pipeline‑Valve request flow equips developers to answer interview questions confidently and troubleshoot Tomcat configurations effectively.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
