This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Thread in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Thread in Servlet " Watch "Thread in Servlet " New topic
Author

Thread in Servlet

priya shankar
Ranch Hand

Joined: May 12, 2003
Posts: 51
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

Joined: Mar 22, 2000
Posts: 12759
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread in Servlet
 
Similar Threads
Comparing Session Management between JavaBean and Servlet.
Pooling
SingleThread Model is deprecated in 2.4
Multiple instances in Servlets
who does instance pooling