struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Graham" <>
Subject RE: why only one instance of Action class (Action class thread sa fety)
Date Wed, 07 May 2003 00:40:14 GMT
Using a Singleton is faster than creating a new object for each request, 
especially for high traffic applications.  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 


>From: Brendan.Johnston@WellsFargo.COM
>Reply-To: "Struts Developers List" <>
>Subject: RE: why only one instance of Action class (Action class thread sa 
>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
>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
>and in your request processor / wib action server / some filter, 
>on that object.  I think I might implement that.
>All the actions I have written have no instance variables.
>That's because instance variables would be useless/dangerous
>because they are shared by all requests.
>However OO provides instance variables and they are useful in my designs.
>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.
>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.
>-----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, 
>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 
>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:

View raw message