Internal Components and Flow

Catalina Container

Catalina is Apache Tomcat’s Servlet container implementation. Its main responsibilities include:

  • Parse HTTP requests and invoke corresponding Servlet
  • Manage Servlet lifecycle (load, initialize, destroy)
  • Provide standard Servlet API support
  • Support Session management, Cookie handling
  • Integrate JSP compilation, JNDI lookup, user authentication and other container-level functions

Catalina’s architecture is a typical nested container structure. The core interface is org.apache.catalina.Container:

Engine (top-level container)
 └── Host (virtual host)
      └── Context (Web application)
           └── Wrapper (individual Servlet)
  • Engine: StandardEngine, represents the entire Catalina engine, can configure multiple virtual hosts (Host)
  • Host, StandardHost: Represents a virtual host, corresponds to configuration in server.xml
  • Context, StandardContext: Represents a Web application, usually corresponds to a WAR package or a webapps subdirectory
  • Wrapper, StandardWrapper: Represents a Servlet (such as LoginServlet)

These containers are all implementations of the Container interface, supporting recursive nesting and lifecycle management (start, stop, init)


Layered Structure

Tomcat is a Web container composed of a series of configurations (conf/server.xml). Catalina is Tomcat’s Servlet container.

From another perspective, Tomcat is essentially a Servlet container because Catalina is Tomcat’s core. Other modules provide support for Catalina, such as: Coyote module provides link communication, Jasper module provides JSP engine, Naming provides JNDI service, Juli provides logging service.


Container Structure

We can consider the entire Tomcat as a Catalina instance. When Tomcat starts, it initializes this instance. Catalina instance completes creation of other instances by loading server.xml, creates and manages a Server, Server creates and manages multiple services, each service can have multiple Connectors and one Container.

● One Catalina instance ● One Server instance ● Multiple Service instances

Each Service instance can have multiple Connectors and one Container instance

Catalina: Responsible for parsing Tomcat configuration files (server.xml), creating Server components and managing them ● Server: Server represents the entire Catalina Servlet container and other components, responsible for assembling and starting Servlet engine, Tomcat connector. Server provides an elegant way to start and shut down the entire system by implementing LifeCycle interface ● Service: Service is a component inside Server. A Server contains multiple Services. It binds several Connector components to one Container ● Container: Container, responsible for processing user’s Servlet requests, and returning object to Web user module


Container Specific Structure

Under Container component, there are several specific components: Engine, Host, Context, and Wrapper. These 4 types of components have parent-child relationships. Tomcat uses a hierarchical architecture, making Servlet container have good flexibility.

Engine: Represents Catalina’s entire Servlet engine, used to manage multiple virtual sites. A Service can have at most one Engine, but an engine can contain multiple Hosts ● Host: Represents a virtual host, or a site. You can configure multiple virtual host addresses for Tomcat. A virtual host may contain multiple Contexts ● Context: Represents a Web application. A Web application can contain multiple Wrappers ● Wrapper: Represents a Servlet. Wrapper as the lowest layer in container cannot contain child containers. The above component configuration is actually in conf/server.xml


Startup Flow

Catalina’s startup flow can be traced to underlying Java classes through bin/startup.sh script:

startup.sh script calls catalina.sh catalina.sh executes: java org.apache.catalina.startup.Bootstrap start

Bootstrap class completes the following:

  • Load catalina.jar
  • Create and initialize Catalina instance
  • Call catalina.load() to load server.xml configuration
  • Call catalina.start() to start service (including Connector and Container)

Thread Processing Mechanism

Catalina is based on thread pool to process requests:

  • Each Connector internally uses thread pool (such as org.apache.tomcat.util.threads.ThreadPoolExecutor)
  • Request entering will be converted to HttpServletRequest/Response, handed to corresponding Wrapper to execute Servlet

This mechanism can both handle high concurrency requests, and limit maximum thread count through configuration (prevent OOM).