tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Kirk <christopher.k...@convergys.com>
Subject RE: MultiThreadModel-Problem?
Date Thu, 14 Jun 2001 15:25:28 GMT


It isn't just 'static' variables that you have to be careful of, normal
instance variables should be avoided too.  You see, one instance of a
servlet
may service many many people (often there is only ever one instance of a
particular servlet!).

If you are sharing any data structure between threads, then you have
to protect them with synchronized blocks. That means that you could
use HashMap, even if it is being shared but you will have to make sure
that only one thread ever tries to access it at any time.. -ie by
gaining a lock on the HashMap itself.

I hope that helps, but with out seeing code I cann't be much more
exact.

- Chris.

Brainbench MVP Java2.


> -----Original Message-----
> From: Sebastian Schulz [mailto:sebastian.schulz@sebastian-schulz.com]
> Sent: 14 June 2001 16:09
> To: tomcat-user@jakarta.apache.org
> Subject: MultiThreadModel-Problem?
> 
> 
> hi,
> 
> i use a servlet in MultiThreadModel-mode (default).
> when 2 users at the same time makes the same request
> to the servlet (a operation that needs a bit) it seams, that
> only the request of the user who was perhaps a millisecond
> earlier is responded correct, the other seams to be ignored.
> 
> (i think, this is perhaps a concurency-problem, but i do not use
> static variables and could not find an error)
> 
> the second question is:  data-container like HashMap or HashSet
> are considered to be not Thread-save. Can i use such containers
> in a MultiThreadModel-Servlet or must i use only slower structures
> like Vector?
> 
> your help is realy needed, many thanks
> in advance!
> 
> basti
> 


--

NOTICE:  The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential.  If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected.

Mime
View raw message