You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Amish Patel <se...@hotmail.com> on 2004/02/21 19:18:07 UTC

ActionForms Thread Safe

Hello All,

I am new to struts.  I have been reading about it and they way I understand 
the framework instantiate ActionForm is as follows. ......

1) Check to see if an instance of the ActionForm already has been created.

2) If an ActionForm instance is present in the appropriate scope and it's 
the same type as needed for the new request, reuse it.
Otherwise, create a new instance of the required ActionForm and store it in 
the appropriate scope (set by the scope attribute for the action element).


If this is case then ActionForm are not thread-safe.  Because Two request 
from different client can simultaneous come in and use the same ActionForm 
instance?

I know this is not the case, but I cannot figure out how is it thread safe?

Please help!
Thanks
-Semplice

_________________________________________________________________
Get a FREE online computer virus scan from McAfee when you click here. 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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


RE: ActionForms Thread Safe

Posted by Andrew Hill <an...@gridnode.com>.
<snip>
If this is case then ActionForm are not thread-safe.  Because Two request
from different client can simultaneous come in and use the same ActionForm
instance?

I know this is not the case, but I cannot figure out how is it thread safe?
</snip>

Actually it is the case! - but only in certain cases when you have a session
scoped actionform.

Under these conditions it is possible for more than one thread to be playing
with that actionform at the same time. Where this could occur is when the
user has multiple windows open (or does a very rapid double submit) and
fires requests in both windows that map to the same action mapping.

You will note that it only affects that particular session. Other sessions
running at the same time will have their own actionforms of course, and
different actionmappings can use different attribute keys to store the form
under.

So you only have a problem where you need to support multiple windows/frames
(and thus potentially threads) for the same actionmapping for the same http
session and you use session scoped forms. (Ive been there. Its a pain)

We had a wee bit of a discussion about this last week in the context of
'workflow scopes':
http://marc.theaimsgroup.com/?l=struts-user&w=2&r=1&s=Request+against+Sessio
n&q=b

And the moral of the story?
Always keep your action forms REQUEST scoped if possible. (Sometimes it isnt
, but 95% of the time it IS possible with a bit of thought and extra effort)

(Request scoped forms only exist while a single thread is processing an
action so they are always thread safe)



-----Original Message-----
From: Amish Patel [mailto:semplice78@hotmail.com]
Sent: Sunday, 22 February 2004 02:18
To: struts-user@jakarta.apache.org
Subject: ActionForms Thread Safe


Hello All,

I am new to struts.  I have been reading about it and they way I understand
the framework instantiate ActionForm is as follows. ......

1) Check to see if an instance of the ActionForm already has been created.

2) If an ActionForm instance is present in the appropriate scope and it's
the same type as needed for the new request, reuse it.
Otherwise, create a new instance of the required ActionForm and store it in
the appropriate scope (set by the scope attribute for the action element).


If this is case then ActionForm are not thread-safe.  Because Two request
from different client can simultaneous come in and use the same ActionForm
instance?

I know this is not the case, but I cannot figure out how is it thread safe?

Please help!
Thanks
-Semplice

_________________________________________________________________
Get a FREE online computer virus scan from McAfee when you click here.
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


---------------------------------------------------------------------
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: ActionForms Thread Safe

Posted by Hubert Rabago <ja...@yahoo.com>.
Different clients use different requests and different sessions.  Therefore,
different users end up with different AF instances.  If you use request scope
for your AF, then even different requests from the same client will be using
different AF instances.
hth,
Hubert

--- Amish Patel <se...@hotmail.com> wrote:
> Hello All,
> 
> I am new to struts.  I have been reading about it and they way I understand
> 
> the framework instantiate ActionForm is as follows. ......
> 
> 1) Check to see if an instance of the ActionForm already has been created.
> 
> 2) If an ActionForm instance is present in the appropriate scope and it's 
> the same type as needed for the new request, reuse it.
> Otherwise, create a new instance of the required ActionForm and store it in
> 
> the appropriate scope (set by the scope attribute for the action element).
> 
> 
> If this is case then ActionForm are not thread-safe.  Because Two request 
> from different client can simultaneous come in and use the same ActionForm 
> instance?
> 
> I know this is not the case, but I cannot figure out how is it thread safe?
> 
> Please help!
> Thanks
> -Semplice
> 
> _________________________________________________________________
> Get a FREE online computer virus scan from McAfee when you click here. 
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

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