Lifecycle of a Java Servlet – three basic phases of initialize, service and destroy
Kushal Paudyal August 16th, 2010
The total life cycle of a java Servlet lies between the beginning of the servlet loading into the application server memory and ending of the servlet by termination/reload.
Basically there are three phases in the life-cycle of a java servlet.
- Instantiation and Initialization Phase (using init() method)
- Creates the instance of the servlet
- If successfully instantiated, the servlet is available for providing service
- If failed to instantiate, it will unload the servlet
- Servicing Phase (using service() method)
- Gets information about the request from the request object
- Processes the request
- Uses methods of the response object to create the client response.
- Can invoke other methods to process the request, such as doGet(), doPost(), or other custom methods.
- Termination Phase (using destroy() methods)
- Stops a servlet by invoking the servlet’s destroy() method.
- The destroy() method runs only one time during the lifetime of the servlet and signals the end of the servlet.
- After calling destroy() method, the servlet engine unloads the servlet
- Unloaded servlets are collected by JVM Garbage Collection
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing – our website does not ask for your credit card and banking information. Happy Surfing!