Tomcat source code analysis-specific Startup Process Analysis, tomcat source code analysis process

Source: Internet
Author: User

Tomcat source code analysis-specific Startup Process Analysis, tomcat source code analysis process

From the Tomcat startup call stack, we can see that the main method of the Bootstrap class is the entire Tomcat entry. When init initializes the Bootstrap class, it sets the working path of Catalina, that is, Catalina_HOME information and Catalina. base Information, initialize the class loader in the initClassLoaders method, and then initialize org. apache. catalina. startup. catalina serves as the catalina daemon;

I. load


Load process in Bootstrap:

Call the load method of Bootstrap to call the load of Catalina Using Reflection. initialize the initDirs () path information in Catalina, call createStartDigester to create and configure Digester information, and load the Server. xml configuration file, use Digester to parse the Server. xml file, and create objects such as Server, Service, Engine, Host, Valve, Realm, Connector, Listener, and Resource Based on the configuration information of the Server File, and object Associations (Digester's knowledge is not described here ). Because the Server object has been created when Digester parses Server. xml, the init method of server is also initialized to the Server object. So far, Bootstrap execution is complete, which is precisely the load loading of Catalina.

Ii. start
Then, the start method of Bootstrap is called to start the container. In the start method, the start method of Catalina is also called through reflection, for example:

Then, call the start method of the StandardServer object in Catalina to start the server. In the start method, It will be analyzed as in the Tomcat source code analysis-component startup Implementation Analysis Section, through the Tomcat life cycle management observer mode, you can start services, ctor, Engine, Host, Context, Wrapper, and Pipeline;

3. Register ShutdownHook)

1 if (shutdownHook == null) {2     shutdownHook = new CatalinaShutdownHook();3 }4 Runtime.getRuntime().addShutdownHook(shutdownHook);

4. Call await () and stop () to stop the request and the stop container.

The await that calls Catalina actually calls the await of StandardServer. For example, wait for <Server port = "8006" shutdown = "SHUTDOWN"> SHUTDOWN the Tomcat request on port 8006 of Server.
After receiving the SHUTDOWN request, call the stop method and destroy method of StandardServer, for example:

The life cycle management observer Mode disables and releases resources for Service, Connector, Engine, Host, Context, Wrapper, and Pipeline.

V. Summary
The process for starting and disabling Tomcat is now over, and the entire process is still clear. As long as you clear the Tomcat startup process, you will naturally understand the process of disabling Tomcat, tomcat uses the observer mode to manage the Lifecycle of Tomcat. To learn about LifecycleBase, Lifecycle, LifecycleSupport, and other related classes, we also understand the entire process. The sequence diagram of the entire process is as follows:

Tomcat startup and shutdown sequence diagram

 

First Article address: Solinx

Http://www.solinx.co/archives/121

Related Article

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.