• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Lifecycle

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic