You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Phil Grimm <pg...@MimEcom.com> on 2000/10/17 05:01:15 UTC

Shouldn't 'actionInstance' be stored in application scope?

Hi,
I recently started using Struts and am excited about using it to replace our
"home-rolled" framework.

One thing I noticed while doing a port to struts, is that instances of
Action classes are stored as an instance variable in ActionMappingBase. But
it seems like it would be more appropriately stored in the "application"
scope (rather than "action mapping" scope).

Here's why I say that. If you have more than one action that uses the same
Action class, you end up with multiple instances of the Action class (one in
each mapping). My current application only has 3 actions defined and two of
them use the same Action class. 

Is it common that multiple actions will use the same Action class? Doesn't
this occur with the "multi-page" wizard pattern? I was thinking about
developing a generic "CommandAction" class that can be used to carry out a
command pattern execution against my data tier. In that case, I'd have a
number of actions that use this class.

Comments?

Phil Grimm              pgrimm@mimecom.com
Java Architect/Developer
MimEcom Corporation     www.MimEcom.com
44 Montgomery Street, Suite 2150
San Francisco, CA 94104
desk: 415-402-2907      cell: 415-218-8986

Re: Shouldn't 'actionInstance' be stored in application scope?

Posted by Jean-Baptiste Nizet <je...@s1.com>.
Phil Grimm wrote:

> <deleted>
> Is it common that multiple actions will use the same Action class?

In the application I'm currently developing, it's indeed common. I have a
"BasicAction" that does nothing except returning the "success" forward. This
action is used for simple browsing links, in order to force the request to go
through the central ActionServlet.

JB.

<deleted>
--
Jean-Baptiste Nizet
jean-baptiste.nizet@s1.com

R&D Engineer, S1 Belgium
Kleine Kloosterstraat, 23
B-1932 Sint-Stevens Woluwe
+32 2 200 45 42



Re: Shouldn't 'actionInstance' be stored in application scope?

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Phil Grimm wrote:

> Hi,
> I recently started using Struts and am excited about using it to replace our
> "home-rolled" framework.
>
> One thing I noticed while doing a port to struts, is that instances of
> Action classes are stored as an instance variable in ActionMappingBase. But
> it seems like it would be more appropriately stored in the "application"
> scope (rather than "action mapping" scope).
>
> Here's why I say that. If you have more than one action that uses the same
> Action class, you end up with multiple instances of the Action class (one in
> each mapping). My current application only has 3 actions defined and two of
> them use the same Action class.
>
> Is it common that multiple actions will use the same Action class? Doesn't
> this occur with the "multi-page" wizard pattern? I was thinking about
> developing a generic "CommandAction" class that can be used to carry out a
> command pattern execution against my data tier. In that case, I'd have a
> number of actions that use this class.
>

It's interesting that you should be thinking in this way (read:  "great minds
think alike" :-).  I recently checked in changes (on the 1.0 code base) that
caches Action instances based on class name, and removes that function from the
ActionMapping implementation.

That being said, I'm not sure that the arguments for it are all that
compelling.  The only significant benefits seem to be:

* Saving the memory cost of "n" instances of the same class
  in memory -- although an Action instance tends to be really
  small (the bytecodes are shared, so it's just a few bytes for
  the object identity plus a few bytes per instance variable that
  we are talking about here).

* Ability to share state information via instance variables inside
  the action class.  But this capability cannot be used for per-request
  state information anyway (actions are multi-threaded just like
  servlets are), and you can always share things via servlet context
  attributes anyway.

The reason I moved this functionality to the controller servlet is to centralize
responsibility for caching resources that are required in a Struts-ified
application.  Responsibility for creating ActionForm instances was migrated to
the controller for the same reason (although these are not currently cached).

>
> Comments?
>
> Phil Grimm              pgrimm@mimecom.com

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



List archive.

Posted by Raj <ra...@edgesoftinc.com>.
Hi,

I have recently joined in this list.
Does this list has archive in similar lines to Sun Java ? Please let me
know.

Raj