You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by David Geary <sa...@tri-lakesonline.net> on 2000/06/18 00:41:34 UTC

Thread Safe

It appears that none of the code in Struts is thread safe. So what's up
with that?


david


Re: Thread Safe

Posted by David Geary <sa...@tri-lakesonline.net>.
> David Geary wrote:
>
> > It appears that none of the code in Struts is thread safe. So what's up
> > with that?
> >
> > david
>
> In what respect(s) is it "not thread safe"?
>
> For custom tags, you are guaranteed by the JSP spec that a particular
> instance will only be used for that corresponding tag on that page, for
> that request -- so there's no conflicts on values.

The tags were my biggest concern; I didn't know that the spec made such a
guarantee.

> For the controller servlet itself, the only instance variables used are for
> those things that really should be shared.

Sorry, I didn't realize that. I just saw unprotected instance variables in the
action servlet and knee-jerked.


david



Re: Thread Safe

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
David Geary wrote:

> It appears that none of the code in Struts is thread safe. So what's up
> with that?
>
> david

In what respect(s) is it "not thread safe"?

For custom tags, you are guaranteed by the JSP spec that a particular
instance will only be used for that corresponding tag on that page, for
that request -- so there's no conflicts on values.

For the form beans, you are creating them in a particular user's session.
If the user does two submits to the same form at the same time you might
have overlapping setXxx method calls going on, but that's going to be real
unusual.

For the action classes, they follow the same rule that servlets do -- use
local variables only, not instance variables.  If you do this, all your
variables end up on the per-thread stack for there are no conflicts.

For the controller servlet itself, the only instance variables used are for
those things that really should be shared.  All of the per-request stuff is
local variables (which are then passed to method calls as needed).

So, where do you see a difficulty?

Craig