tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hume, John - NA US HQ Delray" <>
Subject RE: Thread Safe JSP/Servlets
Date Mon, 29 Dec 2003 19:03:29 GMT
Instance variables in a JSP will be shared among requests, so you could have
an issue.  

Note however, that you have to go out of your way to declare instance
variables in a JSP (by putting them in a <%! //declaration block %> rather
than a plain old <% //scriptlet block %>).  All non-declarative scriptlets
and all static page content go into the service method of the JSP, so
they're threadsafe.  


-----Original Message-----
From: Merrill Cornish []
Sent: Monday, December 29, 2003 1:55 PM
Subject: Thread Safe JSP/Servlets

I understand how to write thread-safe software in general, but I suddenly
realized that I don't understand what, if anything, Tomcat "shares" among
different sessions (i.e., different users accessing the same JSP
application) and would therefore be thread sensitive.

For example, in my servlets, I have only constant class fields--no instance
fields.  All user-specific information is stored in session attributes that
exist only between user login and logout.  However, it finally dawned on me
that my JSP pages are quietly being turned into servlets behind my back
(this is despite my occassionally referencing the generated *_jsp files
while debugging), and those servlets DO have instance fields.

My specific question is whether Tomcat keeps the instance fields for JSP
servlets separate by session.  My more general request is for a pointer to
"best practices" documentation on how to keep JSPs and servlets thread safe.

Merrill Cornish

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message