RE: Member variables in Actions

2001-11-21 Thread Dave J Dandeneau

That makes sense. Thanks for the help...

dave

-Original Message-
From: Cakalic, James P. [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 21, 2001 3:03 PM
To: 'Struts Users Mailing List'
Subject: RE: Member variables in Actions


Quoting from the Struts User's Guide:

"The controller servlet creates only one instance of your Action class,
and
uses it for all requests. Thus, you need to code your Action class so
that
it operates correctly in a multi-threaded environment, just as you must
code
a servlet's service method safely.

The most important principle that aids in thread-safe coding is to use
only
local variables, not instance variables, in your Action class. Local
variables are created on a stack that is assigned (by your JVM) to each
thread request, so there is no need to worry about sharing them."

Best regards,
Jim Cakalic

> -Original Message-
> From: Dave J Dandeneau [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 21, 2001 1:49 PM
> To: Struts Users Mailing List
> Subject: Member variables in Actions
> 
> 
> Is there any reason that you would / wouldn't want to put member
> variables in an action? I know that using member variables in some
> servlet containers can sometimes slow things down. I don't 
> know how the
> actions are pooled / instantiated, and what affect this might have on
> the performance.  
> 
> Thanks,
> Dave Dandeneau
> 


Confidentiality Warning:  This e-mail contains
information intended only for the use of the individual or entity named
above.  If the reader of this e-mail is not the intended recipient or
the employee or agent responsible for delivering it to the intended
recipient, any dissemination, publication or copying of this e-mail is
strictly prohibited. The sender does not accept any responsibility for
any loss, disruption or damage to your data or computer system that may
occur while using data contained in, or transmitted with, this e-mail.
If you have received this e-mail in error, please immediately notify us
by return e-mail.  Thank you.




RE: Member variables in Actions

2001-11-21 Thread Cakalic, James P.

Quoting from the Struts User's Guide:

"The controller servlet creates only one instance of your Action class, and
uses it for all requests. Thus, you need to code your Action class so that
it operates correctly in a multi-threaded environment, just as you must code
a servlet's service method safely.

The most important principle that aids in thread-safe coding is to use only
local variables, not instance variables, in your Action class. Local
variables are created on a stack that is assigned (by your JVM) to each
thread request, so there is no need to worry about sharing them."

Best regards,
Jim Cakalic

> -Original Message-
> From: Dave J Dandeneau [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 21, 2001 1:49 PM
> To: Struts Users Mailing List
> Subject: Member variables in Actions
> 
> 
> Is there any reason that you would / wouldn't want to put member
> variables in an action? I know that using member variables in some
> servlet containers can sometimes slow things down. I don't 
> know how the
> actions are pooled / instantiated, and what affect this might have on
> the performance.  
> 
> Thanks,
> Dave Dandeneau
> 


Confidentiality Warning:  This e-mail contains information intended 
only for the use of the individual or entity named above.  If the reader of this 
e-mail is not the intended recipient or the employee or agent responsible for 
delivering it to the intended recipient, any dissemination, publication or copying of 
this e-mail is strictly prohibited. The sender does not accept any responsibility for 
any loss, disruption or damage to your data or computer system that may occur while 
using data contained in, or transmitted with, this e-mail.   If you have received this 
e-mail in error, please immediately notify us by return e-mail.  Thank you.




RE: member variables

2001-02-04 Thread Deadman, Hal

You only have to have to worry about synchronization if those session
objects have instance variables. Of course objects that are put in the
session typically have instance variables, otherwise, what's the point of
putting them in the session? I guess you have to deal with the fact that the
session object could be accessed from multiple threads (requests) at the
same time so all the normal synchronization issues apply. Just look at the
instance variables of the object and think about whether there would be a
problem if methods that accessed those variables were called at the same
time. If there would be a problem then synchronize the methods or blocks of
code that manipulate/use the instance variables. 

Hal

-Original Message-
From: John Hunt
To: [EMAIL PROTECTED]
Sent: 2/4/01 4:21 AM
Subject: Re: member variables

What about anything that is put in the session
object??? When should I worry about synchronization
about such objects?
Suppose I put an object which has some some methods in
it? When should I worry about synchronization in the
code that lies in it?
Suppose I put an object in session and open two
browsers, are there synchronization issues then?
I think this is more of servlet question, but I think
I could get a better answer here.
Thanks
Hunt
--- "Craig R. McClanahan"
<[EMAIL PROTECTED]> wrote:
> Ted Husted wrote:
> 
> > There is a single action object per session.
> 
> Um, actually it is per *application*, not per
> *session*.  All users who call
> the same action URI are sharing the same action
> instance.
> 
> The primary implication of this is that instance
> variables in your action
> classes are shared across all requests, while local
> variables (inside the
> perform() method) is not shared.
> 
> Craig McClanahan
> 
> 


__
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: member variables

2001-02-04 Thread John Hunt

What about anything that is put in the session
object??? When should I worry about synchronization
about such objects?
Suppose I put an object which has some some methods in
it? When should I worry about synchronization in the
code that lies in it?
Suppose I put an object in session and open two
browsers, are there synchronization issues then?
I think this is more of servlet question, but I think
I could get a better answer here.
Thanks
Hunt
--- "Craig R. McClanahan"
<[EMAIL PROTECTED]> wrote:
> Ted Husted wrote:
> 
> > There is a single action object per session.
> 
> Um, actually it is per *application*, not per
> *session*.  All users who call
> the same action URI are sharing the same action
> instance.
> 
> The primary implication of this is that instance
> variables in your action
> classes are shared across all requests, while local
> variables (inside the
> perform() method) is not shared.
> 
> Craig McClanahan
> 
> 


__
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: member variables

2001-02-02 Thread Ted Husted

This reminds me of another question I've been meaning to ask. 

Once upon a time, in a discussion of Business Logic Beanies, I
mentioned a "QueryFormBean", which is basically a poor man's uncached
RowSet. This is mean to encapsulate the JDBC red-tape, along with the
SQL command, the latter being read from a resource.

Craig then said: 

> If you do it this way, do you need more than one QueryBean?  Couldn't
you create a generic one that processes different kinds of query
strings based on the name of the resource you told it to read?

What would be the best approach for exposing one QueryBean (or RowSet)
to a Struts application? Set it up as another servlet, subclass the
Struts controller and set it up like an Action, or some other way?

Right now, to get started, I just put QueryBeans on the ActionForm as
member variables (as in the latest Fruit Glaze example). 

There is a base object that provide the core fuctionality. I then have
a "fetch" method that is subclassed to transfer the  resultset data
into an entity bean (or array of entity beans) that the form can use,
and a setParameters method that can be subclassed for prepared
statements.

I could easily put 80% or 90% of the QueryBean into a shared object,
but might still want a custom object for fetching entity data and
setting parameters. (Though, now that I say it, perhaps something
clever could be done with reflection.)

Anyway, I'm still not well versed on how Java works under the hood.
Would sharing one "big" object, but still creating the same number of
objects overall make an actual difference? 

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/





Re: member variables

2001-02-02 Thread Craig R. McClanahan

Ted Husted wrote:

> There is a single action object per session.

Um, actually it is per *application*, not per *session*.  All users who call
the same action URI are sharing the same action instance.

The primary implication of this is that instance variables in your action
classes are shared across all requests, while local variables (inside the
perform() method) is not shared.

Craig McClanahan





RE: member variables

2001-02-02 Thread Deadman, Hal

You mean one instance of each Action class per application, not session. I
would say that the use of instance variables is discouraged because they
raise synchronization issues. 

"The most important principle that aids in thread-safe coding is to use only
local variables, not instance variables, in your Action class. Local
variables are created on a stack that is assigned (by your JVM) to each
request thread, so there is no need to worry about sharing them. "

Hal
-Original Message-
From: Ted Husted [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 02, 2001 7:00 PM
To: Struts List
Subject: Re: member variables


There is a single action object per session. You do need to take care
of any concurrency issues. The use of instance variables where possible
is recommended. 

See <
http://jakarta.apache.org/struts/userGuide/building_controller.html#acti
on_classes > for more, starting with "Design issues to remember when
coding Action classes". 

*** REPLY SEPARATOR  ***

On 2/2/2001 at 3:54 PM John Hunt wrote:

What are the ramifications of having member variables
in action class ( should we take care of any
concurrency issues  )... Does every request create
a new Action object or these objects reused

Thanks
Hunt

__
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/




Re: member variables

2001-02-02 Thread Ted Husted

There is a single action object per session. You do need to take care
of any concurrency issues. The use of instance variables where possible
is recommended. 

See <
http://jakarta.apache.org/struts/userGuide/building_controller.html#acti
on_classes > for more, starting with "Design issues to remember when
coding Action classes". 

*** REPLY SEPARATOR  ***

On 2/2/2001 at 3:54 PM John Hunt wrote:

What are the ramifications of having member variables
in action class ( should we take care of any
concurrency issues  )... Does every request create
a new Action object or these objects reused

Thanks
Hunt

__
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/about/struts/