The relationship between tomcat and jvm, mainly about the relationship between project execution process and memory

The relationship between tomcat and jvm, summarize a few words based on your own understanding:

Run a Java program (a main method), and a jvm instance will be generated . (I guess) the memory size of this jvm instance is the default size or if the size is set for the jvm, follow the set size. The objects and local variables generated during the execution of the main method are placed in the memory of this jvm instance. After the main method is executed, the jvm instance dies.

▲ Ordinary Java program, loading a class (into the JVM memory), is the job of the JVM system class loader. Tomcat is also a Java program, and it also has a main method (in the org.apache.catalina.startup.Bootstrap class), so the startup of tomcat will also generate a jvm instance; but it is more special or a web container, so it loads a class( To the JVM memory) is loaded by its own dedicated tomcat class loader.

▲ The servlet is a singleton. Web.xml will be loaded when tomcat is started. The servlet object will not be generated when web.xml is loaded. The servlet is instantiated when the request is initiated for the first time.

▲ Each request corresponds to opening a thread, and each thread allocates 1mb of memory. Opening a thread requires 1mb of jvm memory space to be used as a thread stack. (I guess) It is used to store the reference of this thread object and the local variables in the thread such as request and response.

Native servlet project_ , after a request to find a servlet, you can directly find the servlet object, and then call methods such as doGet in this object.

ssh or ssm framework project_ , when tomcat starts, the controller, service, and dao objects are created by loading configuration files or annotations, and placed in the spring container (ApplicationContext object). When a request comes, you can directly Find the controller object and call the corresponding method in it, and then selectively adjust the methods in the service and dao objects according to the code in the method.

▲ A tomcat contains a main method, which generates a jvm instance, so all projects under a tomcat use the same jvm instance.

 

To be summarized:

△ jvm's system class loader

△ Tomcat's class loader

 

Guess you like

Origin blog.csdn.net/cherry_vicent/article/details/108809678