Hi,

fortunately, after more testing theory is right and it happends that should happen. You are right.

It is my fault since I was testing the variable after previous asignment so the variable got the different values because I was asigning a new value in every execution, previously to the logging. The pointer is anyway unique, since the Action instance is the same.

My next attemp will be to use ThreadLocal variables to try to made every value of the variable take different values for every execution (Thread). Not very polite perhaps, but I save to pass the request in every accesor invocation.

Apologises and thanks,

Adolfo







From: "Giri Alwar" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: Re: (Un)expected behaviour in Action instance variables?
Date: Mon, 20 Jan 2003 12:49:51 -0600

However, it is ok to cache certain things as instance/class variables in
your Action class provided they meet certain requirements. For instance,
things like session EJB remotes can be cached as instance/class variables
since they are both thread-safe and are not altered by requests (you will
need to get and store the remote in your constructor for instance - if you
plan on doing lazy initialization, ensure that your code is synchronized).
Declaring a EJB home as a local variable for instance and fetching a new
one every time a request arrives would result in degraded performance.

In summary, visualize hundreds of threads using the same instance/class
variables of your Action class simultaneously. The threads should not alter
the state of these variables (unless such a change is synchronized and it is
ok for subsequent threads to see the change - an example of this would be
lazy initialization). If any method calls are invoked on those variables,
visualize the same hundreds of threads calling those methods simultaneously.
If those methods are thread-safe as well, then it is ok to declare it as an
instance/class variable. Otherwise, declare it as a local variable.

----- Original Message -----
From: "Adolfo Miguelez" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, January 20, 2003 12:08 PM
Subject: (Un)expected behaviour in Action instance variables?


> Hi all,
>
> some of our teams have defined an instance variable in an Action. Wrong
> policy as said in the online docuemntation:
>
>
> *******************
>
http://jakarta.apache.org/struts/userGuide/building_controller.html#action_d
esign_guide
>
> Only Use Local Variables - 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. An Action can be factored into several local methods,
so
> long as all variables needed are passed as method parameters. This assures
> thread safety, as the JVM handles such variables internally using the call
> stack which is associated with a single Thread.
> *******************
>
> Such a variable is only declared in the class variable declarations an
> instantiated in perform() executions.
>
> My first impression was that they should refactor the code to move this
> variable to local as the paragraf above claims. However, we decided to
test
> the execution so we opened two browsers. The surprise was that, despite is
> true that there was a unique Action, there were a different instance of
the
> variable for each of two browsers. Furthermore, navigating along the app,
> such a variable was not overridden by the other execution and two
instances
> exist (one for each browser).
>
> Automatically I wondered about the paragraf above, and where was my
> missuderstanding. I suppose if the variable were either static or
> instantiated in the Action constructor, the paragraf would be right. But
not
> in our situation, I guess.
>
> Can any of you figure out what am I missuderstanding? Is the paragraf
right?
> Is a different space in memory created for each instantiation, right? How
> and who knows which one to use to cover each request? The servlet engine?
It
> shouldnt seems, I guess testing out of a web environment the same should
> happends. How can the Action class maintain a reference for each instance
of
> the variable with a unique declaration (i.e. pointer)?
> :-(
>
> I feel an authentic newbie,
>
> regards,
>
> Adolfo.
>
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 12/30/2002

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

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus


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

Reply via email to