Absolutely right, Jerry!  Ironically, I was just writing a non-Struts helper
class to make a credit card validation method thread safe and I was not
Thinking-in-Struts mode.  The no-instance variables rule is one of the first
things learned when starting out with Struts!  The variable should be
limited to local scope or different threads are going to jeopardize the
integrity of the variable state because the Action class is, in essence,
static (singleton).

Better get a second cup of coffee...is it Friday yet???

Mark

-----Original Message-----
From: Dave Derry [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 03, 2002 9:48 AM
To: Struts Users Mailing List
Subject: Re: threading question


Had your coffee yet this morning Mark? I don't think you read this very
closely. Unless I am sorely mistaken (and it wouldn't be the first time!),
it has been pointed out many times on this list that only one instance of
each Action class will created, and cached by the ActionServlet. They must
therefore be thread-safe, and any instance variables are a big no-no.

If I am wrong about this, please let me know because that would certainly
simplify the task that I am currently engaged in! ;-)

Dave Derry


----- Original Message -----
From: "Galbreath, Mark" <[EMAIL PROTECTED]>


> Yes.  As a non-static instance variable, each thread would have it's own
> reference and be able to set and maintain it's value separately from any
> other thread.
>
> Mark
>
> -----Original Message-----
> From: Esbrook, Scott [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, October 03, 2002 7:45 AM
>
> Quick Struts/servlet threading question: If many classes extended the
> following 'AbstractAction' class (eg, 'ConcreteAction'), would use of the
> 'testString' member variable be threadsafe?
>
> public abstract class AbstractAction extends Action{
>    protected String testString;
>    public ActionForward perform(
>       ActionMapping map,ActionForm form,HttpServletRequest
> req,HttpServletResponse res){
>       testString = req.getParameter("myParam");
>       // other common processing....
>       return process(map,form,req,res);
>    }
>    public abstract ActionForward process(
>       ActionMapping map,ActionForm form,HttpServletRequest
> req,HttpServletResponse res);
> }
> public class ConcreteAction extends AbstractAction{
>    public ActionForward process(
>       ActionMapping map,ActionForm form,HttpServletRequest
> req,HttpServletResponse res){
>       // do something with testString...
>       // return an ActionForward object...
>    }
> }
>
> I was strictly thinking of using the protected members on a per-request
> basis, always initializing them in the AbstractAction's perform() method.
> Furthermore, if use of testString is OK, wouldn't it be OK to have a
member
> vars of type HttpRequest, etc. and set it/them in AbstractAction's
> perform(), thereby avoiding all the associated parameter passing?
>
> Using Struts 1.0.2 if that makes any difference.
>
> Thanks,
>
> Scott Esbrook
> Software Developer
> Compuware Corporation



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to