Servlet lifecycle Phases
1, create the object
Creating objects is created only the first time a user accesses a Web server, the second time, or more often, the Servlet object already exists and is no longer created.
Object creation Principle:
The first time a user accesses a Web server, the server passes the URL address entered by the user, Parse the Web.xml file, get the full class name of the Servlet object, and then create the Servlet object through the reflection mechanism, and when the server is accessed again, the Servlet object is no longer created because it already exists.
2, Initialize
At this point, the Servlet object has been created. Invokes the Init () method of the Servlet object for initialization. Initialization is done after the object is created, and is performed only once.
3, processing requests
Is the core, call the servlet's service () method to process the request. Executable multiple times.
4, Object destruction
When the Servlet object is not accessed for a long time, or the container is closed, the Destroy () method is invoked before the destruction to prepare for destruction.
Summary: The servlet is single-instance, initialized once, and has thread-safety issues.
The lifecycle of the servlet is managed by the Web container, and the programmer cannot change the control, but also to emphasize that our job is to accomplish the concrete implementation of the methods in the servlet.