struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <>
Subject Re: why only one instance of Action class (Action class thread sa fety)
Date Wed, 07 May 2003 02:28:28 GMT
David Graham wrote:
 > Using a Singleton is faster than creating a new object for each request,
 > especially for high traffic applications.

Memory and speed of garbage collection can also be an issue when
creating excessive objects per request in high volume applications.
Struts is doing us a *big* favor by maintaining singletons so we don't 
have to worry about wasting resources on what should be reusable object 
instances (since as has been repeated several times on this thread, 
Actions should just be stateless adaptors that delegate to business 
objects).  The fact that object creation and garbage collection are 
faster/more efficient in newer jvm's does not mean that we should 
needlessly waste resources.

 > If you need instance variables then you likely have too much logic in
 > your action that should go into a separate layer.
 > There is nothing preventing you from using instance variables in actions
 > but you must do it in a thread safe manner.  The easiest solution is
 > to just not use them.
 > It's trivial to override RequestProcessor.processActionCreate to return
 > a new Action for each request so Struts doesn't even have to support
 > this by default.
 > David
 >> From: Brendan.Johnston@WellsFargo.COM Reply-To: "Struts Developers
 >> List" <> To:
 >> Subject: RE: why only one instance of Action class (Action class
 >> thread sa fety) Date: Tue, 6 May 2003 17:08:50 -0700
 >> The struts designers clearly do not agree that actions should be single
 >> use.  They are not single use now.
 >> This shows that Struts designers have different tastes to me. I have
 >> yet to see one advantage of singleton actions.
 >> What advantage of singletons am I not getting?
 >> I have responded to the other comments. But this seems like a useless
 >> distraction if Singleton actions have zero advantages.
 >> All parts of a web application do not have to be reentrant.
 >> ActionForms do not have to be reentrant. In general re-entrant
 >> code is very hard to test and therefore likely to be buggy. I
 >> would suggest that all part of a web application that are written
 >> by applications prgrammers should not be re-entrant.
 >> To avoid the problem Craig mentioned with session, one solution is
 >> to insert a standard object whenever you create a new session, and
 >> in your request processor / wib action server / some filter,
 >> synchronize on that object.  I think I might implement that.
 >> All the actions I have written have no instance variables. That's 
 >> instance variables would be useless/dangerous because they are
 >> shared by all requests.
 >> However OO provides instance variables and they are useful in my 
 >> When I look at actions, I see functional decomposition, not object
 >> oriented designs.
 >> Instantiating another object to get around this sometimes does not
 >> work well with subclassed actions.
 >> For an example of a shorter parameter list, see the wiki posted by
 >> Ted.
 >>  ionClass
 >> Based on road map I don't agree/understand why this is a struts 2.0
 >> issue. There is no need to break backward compatability.
 >> Brendan
 >> -----Original Message----- From: Miller, Jason
 >> [] Sent: Tuesday, May 06, 2003 1:37 PM
 >> To: 'Struts Developers List' Subject: RE: why only one instance of
 >> Action class (Action class thread sa fety)
 >> I'll throw in one thought, as well.
 >> Having multiple instances of Actions doesn't really allow much anyway,
 >> since ALL parts of a web app have to be reentrant.  By shifting
 >> the thread safety issues down one level, I don't see much being
 >> gained.  Particularly in light of the fact that Actions should be
 >> fairly lightweight, anyway.
 >> ---------------------------------------------------------------------


 >> To unsubscribe, e-mail:
 >> For additional commands, e-mail:
 > _________________________________________________________________
 > The new MSN 8: advanced junk mail protection and 2 months FREE*
 > ---------------------------------------------------------------------


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

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

View raw message