struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: why only one instance of Action class (Action class thread safety)
Date Mon, 05 May 2003 16:07:43 GMT
On Sun, 5 May 2003, Weigen Liang wrote:

> Date: 05 May 2003 01:49:14 -0400
> From: Weigen Liang <>
> Reply-To: Struts Developers List <>
> To:
> Cc:
> Subject: why only one instance of Action class (Action class thread
>     safety)
> 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
>    ...
> }

Changing this now would be a major backwards incompatibility issue, so it
will not be done in any Struts 1.x release.  We can look at other
approaches in a 2.x time frame.

Per-request object instantiation is cheaper in 1.4 JDKs, but it's still
not free.  However, lots of Struts users still run on 1.2 and 1.3 JDKs
where this is still a pretty big issue.

> 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.

Yet the large majority of those people seem to figure it out after a while
-- especially the single most important rule (do not store
per-request state information in instance variables of an Action).  As
others have pointed out, the Servlet API imposes exactly the same sort of
issue; it wasn't invented here.

> Weigen


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

View raw message