You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Hill <an...@gridnode.com> on 2002/09/27 09:51:06 UTC

Is it really worth the effort to have a single instance of the Action?

Given that for modern JVMs object creation and cleanup isnt the chore it
used to be , I am wondering if it might not be more convienient to create a
new Action instance for each request.

This would eliminate the need to write the Actions in a thread-safe manner
and allow for the use of member variables  (though such would only exist
during that request obviously).

It would then be quite tempting to pass in the mapping, actionForm, request,
response to the constructor and have them as member variables. (Not that
there is any particular benefit to this, except perhaps as syntactical
sugar)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is it really worth the effort to have a single instance of the Action?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 27 Sep 2002, Andrew Hill wrote:

> Date: Fri, 27 Sep 2002 15:51:06 +0800
> From: Andrew Hill <an...@gridnode.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>      andrew.david.hill@gridnode.com
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Is it really worth the effort to have a single instance of the
>     Action?
>
> Given that for modern JVMs object creation and cleanup isnt the chore it
> used to be , I am wondering if it might not be more convienient to create a
> new Action instance for each request.
>

The WebWorks framework (by Rickard Oberg) actually does things in the
manner you suggest, and goes one step further -- he combines what we think
of as the form bean and the Action into a single class, and calls all the
property setters for your request fields directly on the "Action" instance
before calling it's execute() method.  Therefore, no separate form bean
class is needed.

If I had thought of this design pattern in the first place, I'd have been
pretty tempted to use it.  However, changing the semantics of a
fundamental piece of Struts this radically doesn't seem like a good idea
at this point, because it would reduce performance (albeit by a small
amount) on existing Struts apps that are already programmed with thread
safe Actions.

The other concern I have is that this would encourage you to code your
business logic in the Action directly, instead of delegating it to some
logic bean.  I view the most appropriate role of an Action to be as an
adapter between the servlet-API-based web environment and the business
logic of your application, which should *not* depend on any presentation
layer APIs itself.


Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>