You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Hunt <te...@yahoo.com> on 2001/02/03 00:54:44 UTC

member variables

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/

Re: member variables

Posted by Ted Husted <ne...@husted.com>.
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

Posted by John Hunt <te...@yahoo.com>.
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"
<Cr...@eng.sun.com> 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

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
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

Posted by Ted Husted <ne...@husted.com>.
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/