struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <>
Subject RE: why only one instance of Action class (Action class thread safety)
Date Mon, 05 May 2003 06:21:30 GMT
The main argument against this is that it is inefficient and will result in
more object creation - taking time and memory.

Personally I dont think that one extra object per request would be such a
big deal - I mean its already created an action form instance, gone through
all the effort of poulating it etc... One more new Action object probably
wouldnt hurt too much... (and its pretty insignificant compared to all the
tons of objects that get created and garbage collected inside one of my

And like you point out in your example, it would make the signature a lot
simpler for the execute method. Furthermore one could add extra setters for
custom stuff that could be called from a custom request processor.

That said - the efficiency argument does still stand - and I cant see the
struts developers being ready to make such a big break with the current
design. There is also a certain truth in the argument that things are
simplified for developers by following the same technique as the servlet api

-----Original Message-----
From: Weigen Liang []
Sent: Monday, 5 May 2003 13:49
Subject: why only one instance of Action class (Action class thread

The current Struts framework creates only one instance for each Action
class, and uses that instance to serve all the relevant requests. This
makes the Action class thread safety a big issue for newer users of the
Struts framework. The struts user mailing list has many, many such
questions from Struts users. This is similar to servlet itself. The
servlet spec has the SingleThreadModel to "try" to solve this problem,
but as we know, this does not really work.

If one instance of Action object is created for EACH request, then we
would not have this threading issue. This instance would be tied to a
request object and a response object, and has life span of that
particular request. The class would be like this:

public class Action {
   public Action(ActionMapping mapping, ActionForm form,
      ServletRequest request, ServletResponse response) {

   public ActionForward execute() {

   private ActionMapping mapping;
   private ActionForm form;
   private ServletRequest request;
   private ServletResponse response;

   // plus other instance variable for this particular request

Considering that a significant percentage of Struts users have limited
understanding of thread safety, removal of such a concern from the
framework would certainly help the users.


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

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

View raw message