# Servlet Life cycle

* Following are the steps that happens in the initialization sequence of the servlet class.
  * Container searches the servlet class under J2EE compliant folder structure, `WEB-INF/classes`.
  * It loads the class using `Class.forname(FQCN)` obtained from the `web.xml` servlet tag.
  * To create instance of the servlet class, the web-container uses default constructor.
  * Once the servlet instance is created by the container, WC injects servlet config object and makes it available to `init()` method.
  * Now, as web container uses thread pool _(Executor)_ mechanism to serve client request, which is created during web container startup time, web container will simply pool out one thread from this thread pool. This thread's run method invoked by WC, will call public service() -> protected service() of the HttpServlet class.
  * From the service method, do\*\*\*\*() is called as per the request, and client request is processed.
  * At the end of servlet life cycle, destroy method is invoked, after which servlet instance will be marked for garbage collection.

![](https://574639531-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJDnjsv52I3fJ56WbLgHu%2Fuploads%2Fgit-blob-6cf7147a332a1efa128dcf22f290171fb3fce000%2Fservlet_life_cycle.png?alt=media)
