users
[Top] [All Lists]

RE: [cinjug-users] Struts action - thread-safe code

To: "Alexander V" <mzuknn@xxxxxxxxx>, "Mike Helmick" <helmick@xxxxxxxxx>
Subject: RE: [cinjug-users] Struts action - thread-safe code
From: "Arnett, Matt" <Matt.Arnett@xxxxxxxxxx>
Date: Wed, 11 May 2005 22:35:13 -0400
Cc: <users@xxxxxxxxxx>
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Thread-index: AcVWmqUWPeUyXMXJTj6TM8yXzeG/tgAAHExP
Thread-topic: [cinjug-users] Struts action - thread-safe code
Here's a good article about being thread safe in Servlets...same applies to 
Struts Action classes.
http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html
 
-Matt

        -----Original Message----- 
        From: Alexander V [mailto:mzuknn@xxxxxxxxx] 
        Sent: Wed 5/11/2005 10:31 PM 
        To: Mike Helmick 
        Cc: users@xxxxxxxxxx 
        Subject: Re: [cinjug-users] Struts action - thread-safe code
        
        

        Thank you very much!
        
        --- Mike Helmick <helmick@xxxxxxxxx> wrote:
        >
        > short answer: no.
        >
        > rewrite like so
        > class SomeAction extends Action {
        >
        >   public ActionForward execute(request, form){
        >     Object someObject = new Object();
        >     someObject.toString(); // is it OK?
        >   }
        >
        > }
        >
        > now... .if the instance of the object should only be
        > created once 
        > then you can make it private, but you're going to
        > want to
        > synchronize around it. (bad performance)
        >
        > generally the only member variables in an action
        > should be (in my 
        > opinion)
        >    1) a static handle to the logger
        >    2) static final constants that don't fit better
        > somewhere else 
        > (chances are they fit better somewhere else on in a
        > properties file)
        >
        > hope that helps
        > mike helmick
        >
        >
        ------------------------------------------------------------------------
        >
        > ----------------------
        > Michael T Helmick,  M.S. 2004 NKU, B.S. 2000 XU
        > Ph.D. Student - University of Cincinnati, College of
        > Engineering
        >      Web: http://mikehelmick.com/
        >
        ------------------------------------------------------------------------
        >
        > ----------------------
        > "we can sleep when we're dead."
        >
        > On May 11, 2005, at 9:33 PM, Alexander V wrote:
        >
        > > Hi,
        > > Iâve a question about Struts action class.
        > > Struts documentation tells:
        > > Actions must be programmed in a thread-safe
        > manner,
        > > because the controller will share the same
        > instance
        > > for multiple simultaneous requests. This means you
        > > should design with the following items in mind:
        > > â    Instance and static variables MUST NOT be
        > used to
        > > store information related to the state of a
        > particular
        > > request. They MAY be used to share global
        > resources
        > > across requests for the same action.
        > > â    Access to other resources (JavaBeans, session
        > > variables, etc.) MUST be synchronized if those
        > > resources require protection. (Generally, however,
        > > resource classes should be designed to provide
        > their
        > > own protection where necessary.
        > > So my question: Is this actionâs class a
        > thread-safe?:
        > >
        > > class SomeAction extends Action {
        > >  private Object someObject;
        > >  public ActionForward execute(request, form){
        > >    someObject = new Object();
        > >    someObject.toString(); // is it OK?
        > >  }
        > > }
        > >
        > > Thanks
        > >
        > >
        > >
        > > __________________________________
        > > Do you Yahoo!?
        > > Yahoo! Mail - Find what you need with new enhanced
        > search.
        > > http://info.mail.yahoo.com/mail_250
        > >
        > > ---------
        > > You may unsubscribe from this mailing list
        > > by sending a blank email addressed to:
        > > users-unsubscribe@xxxxxxxxxx
        > >
        > > --
        > > Find additional help by sending a blank email
        > > addressed to:
        > > users-help@xxxxxxxxxx
        > >
        >
        >
        
        
                       
        Discover Yahoo!
        Get on-the-go sports scores, stock quotes, news and more. Check it out!
        http://discover.yahoo.com/mobile.html
        
        ---------
        You may unsubscribe from this mailing list
        by sending a blank email addressed to:
        users-unsubscribe@xxxxxxxxxx
        
        --
        Find additional help by sending a blank email
        addressed to:
        users-help@xxxxxxxxxx
        
        


This e-mail transmission contains information that is intended to be 
confidential and privileged.  If you receive this e-mail and you are not a 
named addressee you are hereby notified that you are not authorized to read, 
print, retain, copy or disseminate this communication without the consent of 
the sender and that doing so is prohibited and may be unlawful.  Please reply 
to the message immediately by informing the sender that the message was 
misdirected.  After replying, please delete and otherwise erase it and any 
attachments from your computer system.  Your assistance in correcting this 
error is appreciated.
<Prev in Thread] Current Thread [Next in Thread>