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 Sun, 25 Apr 2004 17:50:27 GMT
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


Mime
View raw message