You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Billy Ng <kw...@earthlink.net> on 2003/07/04 03:21:53 UTC
Is Action Instantiated Once?
Hi folks,
I have a address book page that has the previous and next buttons. I notice if 2 different users try to access the address books, last one who clicks on the button always get what it should display. This sounds very like they are both are using the same Action.
The address book action extends a ActionBase that extends Strut's Action. Would anybody tell me if Strut will instantiates a new acton everytime it is called? Did I miss something on the configuration to make it thread dependent?
Thanks!
Billy Ng
Re: Is Action Instantiated Once?
Posted by Billy Ng <kw...@earthlink.net>.
I think I know what is happening. I have some getter methods that hold the
memeber variables in the ActionBase class.
Thank you guys!
Billy Ng
----- Original Message -----
From: "Kwok Peng Tuck" <pe...@makmal.net>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, July 03, 2003 8:15 PM
Subject: Re: Is Action Instantiated Once?
> How did you code the Action ?
>
> Billy Ng wrote:
>
> >I don't think I used instance variables for referencing the address book
> >entries, but the last guy always wins. The screen of the guy who first
> >clicks on the next button will not display anything until the screen of
the
> >guy who clicks later finishes.
> >
> >Billy Ng
> >
> >----- Original Message -----
> >From: "Craig R. McClanahan" <cr...@apache.org>
> >To: "Struts Users Mailing List" <st...@jakarta.apache.org>; "Billy
Ng"
> ><ev...@hotmail.com>
> >Sent: Thursday, July 03, 2003 6:42 PM
> >Subject: Re: Is Action Instantiated Once?
> >
> >
> >
> >
> >>On Thu, 3 Jul 2003, Billy Ng wrote:
> >>
> >>
> >>
> >>>Date: Thu, 3 Jul 2003 18:21:53 -0700
> >>>From: Billy Ng <kw...@earthlink.net>
> >>>Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
> >>> Billy Ng <ev...@hotmail.com>
> >>>To: Struts Users Mailing List <st...@jakarta.apache.org>
> >>>Subject: Is Action Instantiated Once?
> >>>
> >>>Hi folks,
> >>>
> >>>I have a address book page that has the previous and next buttons. I
> >>>
> >>>
> >notice if 2 different users try to access the address books, last one who
> >clicks on the button always get what it should display. This sounds very
> >like they are both are using the same Action.
> >
> >
> >>>The address book action extends a ActionBase that extends Strut's
> >>>Action. Would anybody tell me if Strut will instantiates a new acton
> >>>everytime it is called?
> >>>
> >>>
> >>No ... one instance only (just like servlets).
> >>
> >>
> >>
> >>> Did I miss something on the configuration to
> >>>make it thread dependent?
> >>>
> >>>
> >>>
> >>You're probably using instance variables in the Action class to store
> >>things relevant only to a particular request. If so, use local
variables
> >>or request/session scope attributes instead.
> >>
> >>
> >>
> >>>Thanks!
> >>>
> >>>Billy Ng
> >>>
> >>>
> >>Craig
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >>
> >>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Is Action Instantiated Once?
Posted by Kwok Peng Tuck <pe...@makmal.net>.
How did you code the Action ?
Billy Ng wrote:
>I don't think I used instance variables for referencing the address book
>entries, but the last guy always wins. The screen of the guy who first
>clicks on the next button will not display anything until the screen of the
>guy who clicks later finishes.
>
>Billy Ng
>
>----- Original Message -----
>From: "Craig R. McClanahan" <cr...@apache.org>
>To: "Struts Users Mailing List" <st...@jakarta.apache.org>; "Billy Ng"
><ev...@hotmail.com>
>Sent: Thursday, July 03, 2003 6:42 PM
>Subject: Re: Is Action Instantiated Once?
>
>
>
>
>>On Thu, 3 Jul 2003, Billy Ng wrote:
>>
>>
>>
>>>Date: Thu, 3 Jul 2003 18:21:53 -0700
>>>From: Billy Ng <kw...@earthlink.net>
>>>Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>>> Billy Ng <ev...@hotmail.com>
>>>To: Struts Users Mailing List <st...@jakarta.apache.org>
>>>Subject: Is Action Instantiated Once?
>>>
>>>Hi folks,
>>>
>>>I have a address book page that has the previous and next buttons. I
>>>
>>>
>notice if 2 different users try to access the address books, last one who
>clicks on the button always get what it should display. This sounds very
>like they are both are using the same Action.
>
>
>>>The address book action extends a ActionBase that extends Strut's
>>>Action. Would anybody tell me if Strut will instantiates a new acton
>>>everytime it is called?
>>>
>>>
>>No ... one instance only (just like servlets).
>>
>>
>>
>>> Did I miss something on the configuration to
>>>make it thread dependent?
>>>
>>>
>>>
>>You're probably using instance variables in the Action class to store
>>things relevant only to a particular request. If so, use local variables
>>or request/session scope attributes instead.
>>
>>
>>
>>>Thanks!
>>>
>>>Billy Ng
>>>
>>>
>>Craig
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Is Action Instantiated Once?
Posted by Billy Ng <kw...@earthlink.net>.
I don't think I used instance variables for referencing the address book
entries, but the last guy always wins. The screen of the guy who first
clicks on the next button will not display anything until the screen of the
guy who clicks later finishes.
Billy Ng
----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>; "Billy Ng"
<ev...@hotmail.com>
Sent: Thursday, July 03, 2003 6:42 PM
Subject: Re: Is Action Instantiated Once?
>
>
> On Thu, 3 Jul 2003, Billy Ng wrote:
>
> > Date: Thu, 3 Jul 2003 18:21:53 -0700
> > From: Billy Ng <kw...@earthlink.net>
> > Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
> > Billy Ng <ev...@hotmail.com>
> > To: Struts Users Mailing List <st...@jakarta.apache.org>
> > Subject: Is Action Instantiated Once?
> >
> > Hi folks,
> >
> > I have a address book page that has the previous and next buttons. I
notice if 2 different users try to access the address books, last one who
clicks on the button always get what it should display. This sounds very
like they are both are using the same Action.
> >
> > The address book action extends a ActionBase that extends Strut's
> > Action. Would anybody tell me if Strut will instantiates a new acton
> > everytime it is called?
>
> No ... one instance only (just like servlets).
>
> > Did I miss something on the configuration to
> > make it thread dependent?
> >
>
> You're probably using instance variables in the Action class to store
> things relevant only to a particular request. If so, use local variables
> or request/session scope attributes instead.
>
> > Thanks!
> >
> > Billy Ng
>
> Craig
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Is Action Instantiated Once?
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Thu, 3 Jul 2003, Billy Ng wrote:
> Date: Thu, 3 Jul 2003 18:21:53 -0700
> From: Billy Ng <kw...@earthlink.net>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
> Billy Ng <ev...@hotmail.com>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Is Action Instantiated Once?
>
> Hi folks,
>
> I have a address book page that has the previous and next buttons. I notice if 2 different users try to access the address books, last one who clicks on the button always get what it should display. This sounds very like they are both are using the same Action.
>
> The address book action extends a ActionBase that extends Strut's
> Action. Would anybody tell me if Strut will instantiates a new acton
> everytime it is called?
No ... one instance only (just like servlets).
> Did I miss something on the configuration to
> make it thread dependent?
>
You're probably using instance variables in the Action class to store
things relevant only to a particular request. If so, use local variables
or request/session scope attributes instead.
> Thanks!
>
> Billy Ng
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Is Action Instantiated Once?
Posted by David Graham <gr...@yahoo.com>.
--- Billy Ng <kw...@earthlink.net> wrote:
> Hi folks,
>
> I have a address book page that has the previous and next buttons. I
> notice if 2 different users try to access the address books, last one
> who clicks on the button always get what it should display. This sounds
> very like they are both are using the same Action.
>
> The address book action extends a ActionBase that extends Strut's
> Action. Would anybody tell me if Strut will instantiates a new acton
> everytime it is called?
Actions are Singletons. They are only instantiated once and reused for
the life of the app. This is why your Actions must be thread safe and not
use instance variables to hold state.
David
> Did I miss something on the configuration to
> make it thread dependent?
>
> Thanks!
>
> Billy Ng
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org