On Mon, Jan 31, 2000 at 10:35:29AM -0500, Peet DENNY wrote:
> Which raises the question: How visible are the variables in a servlet?
Just like any other Java class, as visible as you make them.
> Can everybody potentially write over the variables of everybod else?
Depends on what you mean by "everybody". Variables have
the same scope in servlets as in any other class; if you make them
public, then they're going to be accessible to any other class in
the universe. (OK, in the JVM)
I think your problem is that you're putting class-scope
variables in your servlet and storing per-request information
in them. Except in the (pathological) case of SingleThreadModel
servlets, every request passes through the same instance of a
servlet class, so class-scope variables are shared across all
the requests.
How to handle this? Avoid class-scope variables; if you
need them, they should be static or factory objects (connection
caches, etc.) IN NO CASE SHOULD ANY INFORMATION ABOUT A SINGLE
REQUEST BE STORED IN A CLASS VARIABLE.
Use local variables to store request information;
if you need to, create a class just to organize that data.
Learn about concurrent programming, and follow at least the
basic lessons from there.
--
[EMAIL PROTECTED]
"The bullets are just his way of saying 'Keep it down, I've got a
hangover.'"
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html