struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: OT: thread safety
Date Fri, 07 Jul 2000 20:39:40 GMT
Quaini Michele wrote:

> Sorry for the OT
> In the documentation of struts, is written that the
> Action classes should be thread safe made
> Is there documentation on the WEB or a good books where me
> and my group can learn how to program thread safe classes?

I don't know of any specific references (start searching for
"multithreading" and "multiple threads" and you should get some good
hits, but the most important principles related to Struts -- and to
servlet programming in general -- can be stated fairly easily:

* In a multiple thread environment, instance variables
  of a class are shared across all threads, while local
  variables (those declared inside a method) are not.

* Use instance variables of a servlet (or an Action class
  in Struts) *only* to share read-only information (like the
  action mappings table in Struts), or shareable resources
  that manage their own thread safety (like a connection

* Use local variables for all information that is specific to
  a particular request, as opposed to other requests that
  might be executing at the same time.

* Request attributes (used to pass information on to the
  final JSP page in Struts) are thread safe as long as there
  are no references to these objects anywhere else (like
  in an instance variable).

* Session attributes can be accessed by multiple threads
  at the same time (example:  a multiple frame presentation
  will often cause multiple simultaneous requests that will
  access the same session at the same time).  You *may*
  need to synchronize access to your session beans if they
  can be modified by more than one thread at the same time
  and do not have internal protections.

> Thanks
> michele

Craig McClanahan

View raw message