struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Riyad Kalla <...@email.arizona.edu>
Subject Re: Is MappingDispatchAction (Struts?) multithreaded? (Do I need to worry about it?)
Date Tue, 27 Apr 2004 14:54:23 GMT
Ok thank you, that answered my question.

Takhar, Sandeep wrote:

>general rule is to not have any instance variables.  You can have a method since this
is thread safe.  You are creating a new ActionMessages() so it shouldn't be a problem to move
this to a base method.
>
>sandeep
>
>-----Original Message-----
>From: Riyad Kalla [mailto:rsk@email.arizona.edu]
>Sent: Tuesday, April 27, 2004 9:55 AM
>To: Struts Users Mailing List
>Subject: Re: Is MappingDispatchAction (Struts?) multithreaded? (Do I
>need to worry about it?)
>
>
>Can anyone answer this? (DEVs) I'm very interested in the answer...
>
>Riyad Kalla wrote:
>
>  
>
>>Let me clarify:
>>The first sentence should read "and almost all of my METHODS in my 
>>MDA's do some form of...", so my question is pertaining to any danger 
>>I have when 2+ methods of the same MDA gets called at the same time 
>>and all of them want to return errors.
>>
>>Also the subject had "Struts" in it, because I'm not sure if this is a 
>>"is Struts thread safe?" question or a "Does my servlet container 
>>determine if something is thread safe? And if so, is Struts?". So I'm 
>>not real clear on what takes care of threading, but I know the 
>>use-case I want and I'm curious if anyone knows if its not safe.
>>
>>Best,
>>Riyad
>>
>>Riyad Kalla wrote:
>>
>>    
>>
>>>I'm asking because I am now getting into MappingDispatchActions 
>>>(MDA), and almost all of my actions do some form of DB validation and 
>>>error out if something goes wrong. So I have stamped all over the 
>>>place 4 lines of code that look like:
>>>
>>>ActionMessages actionMessages = new ActionMessages();
>>>actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new 
>>>ActionMessage("product.error.cannotMove"));
>>>saveErrors(request, actionMessages);
>>>return mapping.findForward("failure");
>>>
>>>
>>>And I was thinking how nice, performance and organization if I could 
>>>move a protected instance or even utility method into a base 
>>>AbstractMappingDispatchAction class that did those 4 steps for me and 
>>>I just passed in the message key....
>>>
>>>So the method would do something like:
>>>
>>>actionMessages.clear();
>>>actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new 
>>>ActionMessage(messageKey));
>>>saveErrors(request, actionMessages);
>>>return mapping.findForward(forwardName);
>>>
>>>
>>>but then I realized that this could be a huge problem if I had (a) a 
>>>lot of users using the system and (b) struts/servlet container was 
>>>multithreaded and called 2 methods at the same time that BOTH had 
>>>errors... I could run into a situation where one method cleared the 
>>>errors that the other method was trying to return to the user because 
>>>the actionMessages instance is shared per-class.
>>>
>>>Can anyone let me know if my worry IS correct and I should keep 
>>>everything the way it is, or if I'm safe and can go ahead with it, 
>>>and "why", if you know.
>>>
>>>Thanks!
>>>Riyad
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>  
>

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


Mime
View raw message