Applications in JVM, Tomcat, Servlet, and Tomcat. Thoroughly understand the connection between this concept, jvmtomcat
The applications in tomcat and tomcat (the war package in webapps) run in the same jvm, but the division of labor is different.
The role of tomcat is "dispatcher", and the role of your application is "worker". tomcat processes a requestRoughThe process is as follows:
1. Assume that tomcat listens to port 8080. When an http request is sent from port 8080 of the host, tomcat is first informed.
2. tomcat adds this request to a queue as a task. Several worker threads in the jvm obtain the task from this queue.
3. assuming that worker thread A obtains the task, thread A checks the loaded web by analyzing the request url. xml configuration to determine which servlet the request should be sent to the application for processing (assuming that the application is implemented using servlet)
4. Working thread A calls the corresponding servlet method (service/get/post, etc.), encapsulates the request as A request object and passes it to the servlet
5. At this time, the application starts to work (in fact, the work is still a working thread, but the business logic written in the application is executed), parse request parameters, process business processes, and generate response
6. Worker thread A sends response back to the sending end of the request.
The servlet specification regulates the communication between applications and containers. To put it simply, for example, if you use SpringMVC to write a web application, springmvc complies with servlet specifications, so it can run on any container that complies with servlet specifications. For example, it can run on tomcat. tomcat is a servlet container. Of course, it can also run on jetty.
Tomcat is developed in java. Therefore, tomcat is a java application and needs to be run in JVM, that is, a java virtual machine.