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

Thread in Servlet

 
priya shankar
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have one servlet ..i am creating an instance and i am accessing it...
what will happen if another user tries to access it..(whether it uses intance pooling or multithread)
If it uses pooling ,another user is going to get an instance from pool(a copy of instance as per my understading)..so if he finishes his work and leave will destroy() be called...if so won't it affect the original object..
Also i need a detailed explanation Pls
priya
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet container (such as Tomcat) manages a single instance of your servlet. It is created the first time a request for that servlet occurs and it stays in memory. The destroy method gets called only when the servlet engine is shutting down or needs the space. There is no pool of servlet instances.
The servlet container creates a new Thread for each request and many Threads may be running the same code "at the same time." User specific data is unique to that Thread.
Therefore you have to change your programming habits that you may have used for single user applications. You can't use instance variables for user specific data.
Many discussions here have touched on the problems, so browse around.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic