Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Life cycle of a servlet

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are implementation details.
It is up to the builders of the container to decide whether or not to use thread pooling.
 
Naveen Kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic