• 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 unloading

 
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am aware of how and when a servlet is instantiated and initialized.
My question is what happens after the servlet has responded back to the client. Does it immediately get unloaded(thru garbage collection), or does it stay in initialized state(and if so, for how long??)
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A servlet will usually stay in service until the web app is unloaded. The single instance is used to serve all requests to that servlet.
 
Stanley Walker
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so does that mean that for n number of requests , there will be n instances of that servlet...
and all this would be retained in the server memory right until the web server is shut down?

or is a pool maintained by the container??? when a request comes in for a resource, a servlet instance is retrieved from this pool?if so, how is this pool maintained and do we have any control over this?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stanley Walker wrote:so does that mean that for n number of requests , there will be n instances of that servlet...
and all this would be retained in the server memory right until the web server is shut down?



for n number of requests , there will be ONE instance of that servlet.
The container is allowed to unload the servlet if it decides it needs to, and the servlet should ensure that it releases any resources it hold and then reacquire if the servlet is loaded again.
In practice however, the servlet (in my opinion) the container is unlikely to unload a servlet, and the servlet should be stateless so the unload/reload should not be an issue.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stanley Walker wrote:so does that mean that for n number of requests , there will be n instances of that servlet...


No. I repeat:

Bear wrote: The single instance is used to serve all requests to that servlet.


The container can pretty much do what it wants, but generally it will use a single instance for the life of a web app.

and all this would be retained in the server memory right until the web server is shut down?


The instance will be retained until the web app (not necessarily server) is unloaded.

or is a pool maintained by the container?


There is no pool.
 
Stanley Walker
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for the replies.
let me see if i understand this correctly.
lets say i have a sevlet loginServlet, which is called for logon credentials checking. say user A logs on. lets assume this is the first user logging on. an object of loginServlet will be created and initialized to service user A's request. now if another user B logs on, that same object is used. i guess a thread is started by the container to service client B's request.
am i right ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.

The container may load the servlet prior to the request (either because it felt like it or the deployment descriptor told it to), but it is guaranteed to be loaded and initialized to serve the request.
 
reply
    Bookmark Topic Watch Topic
  • New Topic