Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Instance

 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
How is the instance of servlet stored in the container ? Is it container-specific ??
TIA
MB
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by stored? It exists in memory.
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradeep Bhat:
What do you mean by stored? It exists in memory.


Well,
The case is..I access a servlet, acc. to the lifecycle,
#1. The container will first check for the instance of the servlet...??..How is this done ??
#2. If the instance is not present, the container loads the servlet class,
and creates an instance & then the init() is called.
So if the servlet is accessed again, it'll already find the instance, so init() wont be called again.
So thats what my query was...will the instace be available after I access some other servlet & then again come back to that particular servlet..
TIA
MB
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container looks at the request and the maps it has of web applications and associated servlets (via server.xml and web.xml). Following these maps it ends up with a servlet class that corresponds to the request. If this class has not been loaded, the container loads it, creates and instance, and calls the init() method.
After the request has been handled, the instance will probably remain in memory to handle other requests, but this is NOT guaranteed. The servlet container is allowed to discard the instance if it wants to. Therefore, it is up to the programmer to make provision for storing any data that needs to be permanent.
All of this is spelled out in the servlet API. Anybody working with servlets should go to this Sun site and download the servlet and jsp apis.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic