struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Struts Actions are Singletons?
Date Thu, 25 Apr 2002 15:38:47 GMT


On Thu, 25 Apr 2002 Kevin.Bedell@sunlife.com wrote:

> Date: Thu, 25 Apr 2002 09:59:29 -0400
> From: Kevin.Bedell@sunlife.com
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> Subject: Re: Struts Actions are Singletons?
>
>
>
>
>
> Regarding Action Instances:
>
> They are stored in HashMap (FastHashMap actually) that is kept by the
> primary ActionServlet. This ActionServlet is the same one as is defined as
> a startup servlet in the web.xml of each web application running struts in
> a particular servlet container instance.
>

Which means that, in a distributed container running a Struts based app,
there really is more than one copy of the controller servlet (one per
server instance).  Presumably, you have deployed exactly the same WAR file
on every server, so that the Struts configurations are identical, which
means therefore that the application scope attributes that Struts sets up
are identical.

> While some of this may depend on your particular servlet container, I'd
> venture to guess that its likely that information isn't replicated between
> clustered container instances unless the information is specifically put on
> the Session (or potentially, the Application) context. That's not the case
> with the Action instances - they are stored in the memory space used by the
> servlet itself.
>
> So it looks like this information is likely not replicated among clustered
> instances.
>

There are some containers that try to make some promises about
synchronizing application scope stuff, but it is outside the boundaries of
the J2EE specifications.  If you want to share information across
instances portably, it should be written to some external store (database,
EJBs, whatever) that is accessed from all of the instances.

> But really what does it matter? It's unlikely that you'll be storing
> session information in an Action instance that is shared by multiple
> sessions anyway.
>
> In other words, since you're not going to store per-session information in
> the Action instance, replication of session information in a cluster is
> irrelevant.
>
> That being said, it may be possible that APPLICATION-LEVEL configuration
> information may get out of whack if it is stored in an Action instance.
> Each container would maintain this information independantly, so this may
> be something to look out for.
>

I normally use instance variables in an Action (or application-scope
attributes in the servlet context) only to cache read-only copies of stuff
that needs to be accessed repeatedly.  Anything that changes over time
needs to be written back out to the database -- not only to share it, but
to ensure that it is not lost in case the servlet container crashes.

> FWIW -
> Kevin
>

Craig


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message