The life cycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps.
1.If an instance of the servlet does not exist, the Web container
Loads the servlet class.
Creates an instance of the servlet class.
Initializes the servlet instance by calling the init method. 2.Invokes the service method, passing a request and response object.
Originally posted by Raj Kumar Bindal:
when any request comes for a servlet,
(1)a thread is taken from pool and assigned to that request and also (2)request,response objects are created.
Kindly let me know what is the sequence of these steps, thread is created first or request,response objects are created first.
It depends on the vendor.But I take this in following way.
First the request and response objects are created and then the HTTP request is parsed and put into various variables of the request and then the worker thread is created with the request and the response as arguments to it.