users
[Top] [All Lists]

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

To: Alexander V <mzuknn@xxxxxxxxx>
Subject: Re: [cinjug-users] Struts action - thread-safe code
From: Mike Helmick <helmick@xxxxxxxxx>
Date: Wed, 11 May 2005 22:25:35 -0400
Cc: users@xxxxxxxxxx
Delivered-to: mailing list users@cinjug.org
In-reply-to: <20050512013317.80217.qmail@web60525.mail.yahoo.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <20050512013317.80217.qmail@web60525.mail.yahoo.com>

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. 

---------
You may unsubscribe from this mailing list
by sending a blank email addressed to:

--
Find additional help by sending a blank email
addressed to:


<Prev in Thread] Current Thread [Next in Thread>