struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Hill" <andrew.david.h...@gridnode.com>
Subject RE: ActionForms Thread Safe
Date Mon, 23 Feb 2004 01:40:20 GMT
<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


Mime
View raw message