All the servlet implements the javax.servlet. Servlet interface. This interface has the servlet lifecycle methods. The interface is defined as follows:
The web server loads a servlet when it is first requested by a client and manage the lifecycle of the servlet. Three methods are important in the servlet lifecycle.
When a server loads a servlet, it calls the servlet’s init methods to initialize the servlet. The init method is called only once.
After the server loads and initializes the server, the servlet is able to handle client requests. It processes them in its service method. Each client request generate service methods.
This method is called by web server to end the servlet. This method is called only once but it must be thread safe (because other thread may be running). It perform garbage collector.