Tomcat runs multiple individual threads per *request*, not per *user*.

99.9% of the time, this kind of thing is caused by application programming
errors related to threading.  For example, if you use an instance variable
in a servlet to store information specific to a particular request, and
access that servlet with more than one request at the same time, you will
observe this kind of problem.  The reason for this is that there is one
instance of the servlet class, and therefore one instance of the
(incorrectly shared) instance variable.

To avoid this kind of problem, store information specific to a particular
request *only* in local variables, request attributes, or session
attributes.  Use instance variables in your servlet *only* for things you
really do want to share.

Craig McClanahan


On Thu, 26 Jul 2001, Sam Joseph wrote:

> Hi,
> 
> So I think this is a thread/security issue, but I am not sure.  However
> it is definitely weird.
> 
> I have been conducting some tests with multiple users.  Various servlets
> are contacted that supply pages to each user, that include information
> such as user name etc.  The version of tomcat in use is 3.2.1, and
> clearly I should upgrade to 3.2.3, but the tomcat is provided by my
> service provider so that might take some time.
> 
> Anyway, the problem is that sometimes when two users are accessing the
> system simulatenously the information for one user will be displayed,
> briefly, to the other user.  The system I have developed is quite
> complicated so I can't rule out that this is a problem with the code,
> but I'm not using static variables or anything that would allow this
> swap over.  I mean each user has an object associated with them that
> contains their user name, but these are local variables to the servlet.
> 
> Are there or have there been problems with tomcat that would explain
> this problem?  I mean tomcat creates a separate thread for each servlet
> right? Different user, different thread, so their data shouldn't be
> available to each other.
> 
> Am I overlooking something here?  Should I be mailing to the developer's
> list?
> 
> And on the same topic, does anyone know of any software that will
> simulate multiple users, without me having all my friends test the
> system.  I mean some software (ideally free or shareware) that would
> simulate the stream of http requests, I guess I could hack something
> together myself, but if there's something already out there that would
> be great.
> 
> Thanks in advance.
> 
> CHEERS> SAM
> 
> 

Reply via email to