You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kommineni, Sateesh (IndSys)" <Sa...@geind.GE.com> on 2003/08/11 13:58:55 UTC

Why Action Classes are implemented as Singleton

Hi All,

    In Struts only one Action classes object is created irrespective of the
no.of User Requests (Correct me if i am wrong) ..

    Why is it so .. If we have a common resource in an Action class which is
shared by all the requests and it should be in session scope then how to
handle this situation ??  

Thanks in advance
Sateesh


"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this 
communication is strictly Prohibited. 
If you have received this message by error, please notify us 
immediately, return the original mail to the sender and delete the 
message from your system."


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Why Action Classes are implemented as Singleton

Posted by Paul Thomas <pa...@tmsl.demon.co.uk>.
On 11/08/2003 12:58 "Kommineni, Sateesh (IndSys)" wrote:
> Hi All,
> 
>     In Struts only one Action classes object is created irrespective of
> the
> no.of User Requests (Correct me if i am wrong) ..
> 
>     Why is it so .. If we have a common resource in an Action class which
> is
> shared by all the requests and it should be in session scope then how to
> handle this situation ??
> 

Refer to the Java Servlet specs. The abswer is in there.

-- 
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller 
Business |
| Computer Consultants         | 
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Why Action Classes are implemented as Singleton

Posted by Alex Shneyderman <al...@law.columbia.edu>.
>     Why is it so .. If we have a common resource in an Action class
which
> is
> shared by all the requests and it should be in session scope then how
to
> handle this situation ??

This, sounds like an application scope resource. Create a context
listener, initialize the resource and attach it to ServletContext.

Alternatively you can keep a reference to the resource in your Action.
Since Action is a singleton (just like a servlet) you can keep it there
but make all the needed precautions of not keeping the state of your
request in there. 
The things to keep in mind: 
1. If that resource parametrized you can't really pass parameters if you
keep it in your Action. 
2. The resource is not accessible to other components of your system.
While if it is attached to the ServletContext it will be available for
other resources to use.

Alex.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org