Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Lifecycle

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What i read about servlet life cycle is
1.once the request made to servlet means, servlet mapped through web.xml file and
particular servlet class loaded in to memory
2. New instance will be created (how , who creates instance)
3. container calls init(), it is called only once throghout the life cycle of servlet
4. then service method called to handle the client request. service method called for each time
i know multiple requests and handled by thread.
5. Finally , if the instance will not be accessed for long time or server shutdown means,
container removes instance by destroy().

Interviewer asked , two requests are waiting which one will be processed.
I am clear about lifecyle.
In HTTPServlet service() method called before doGet(), doPost() or not
 
subhash kumar
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
two requests are waiting which one will be processed.

i think there no queue for the request by which two request can be thought of waiting
it is just the thread pool from which a thread will be assigned to process the request
so unless that thread pool got exhausted all request will be processed.
 
Manjusha Muraleedas
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
New instance will be created (how , who creates instance)

By the container


Finally , if the instance will not be accessed for long time or server shutdown means,
container removes instance by destroy().


destroy() will be called before the servlet being unloaded from memory.This method can be used to release resources.
Please check this link

doXxx() is called from service() depending og the request type.Please read the API Doc for HttpServlet.
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If multiple request goes to servlet( service method ) means, it will be assigned to thread.
I asked two requests are there , which one will be processed first.
you said thread pool (And queue) decides which thread to execute.
Is thread pool is the only way or can i set priority for the threads.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic