File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Life cycle of a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Life cycle of a servlet" Watch "Life cycle of a servlet" New topic
Author

Life cycle of a servlet

Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 417
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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

These are implementation details.
It is up to the builders of the container to decide whether or not to use thread pooling.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Naveen Kumar
Ranch Hand

Joined: Dec 14, 2006
Posts: 35
Hi

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.
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 417
what you people are saying is correct but i think first the request,response objects are created and then only thread for executing that particular request is allocated,but that thread is nothing but the execution of service method which requires request and response objects.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Life cycle of a servlet
 
Similar Threads
Thread Safe
Multiple threads for each Client Request
Doubt in Servlet request attribute
using util class that create thread in servlet
Set me straight on synchronization for stateless bean