Lifecycle of a Java Servlet – three basic phases of initialize, service and destroy

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)
  1. Creates the instance of the servlet
  2. If successfully instantiated, the servlet is available for providing service
  3. If failed to instantiate, it will unload the servlet
  • Servicing Phase (using service() method)
  1. Gets information about the request from the request object
  2. Processes the request
  3. Uses methods of the response object to create the client response.
  4. 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
Tagged , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

One Response to Complete Tutorial On Using SOAP-UI to Mock Web Service Request / Response

  1. Pingback: Twenty Differences Between SOAP and REST Webservice - Java and Android Programming Blog @ iCodeJava.com

Leave a Reply

Your email address will not be published. Required fields are marked *