This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Multiple Threads to access a value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Multiple Threads to access a value" Watch "Multiple Threads to access a value" New topic

Multiple Threads to access a value

Ruchi Kumar

Joined: Feb 16, 2005
Posts: 7
This is with reference to HFS, Pg 202, last Q <There are no Dumb Qs>

To my understanding, this mentions ways in which multiple threads can access a common value. But then it says:

"1. Declare the variable as a local variable within the service method, rather than as an instance variable..."

I thought that local varibales are thread safe, and instance variables were not, so inorder for multiple threads [I] to [I]sharethe value, shouldn't the variable be as an instance variable. ie: shouldnt 'instance variable' and 'local variable' be swapped in teh above sentence in the book ? Or am I missing some point?

I looked up the errata, couldn't find any related to this point.
Please help me with this query, as the concepts get mixed up otherwise.

P. Dunn
Ranch Hand

Joined: Feb 22, 2005
Posts: 34
I think your right. What they're trying to accomplish is unclear from the question. Are they trying to share a variable or a value? That's what is muddled.

Don't get me started about those stupid light bulbs.
subject: Multiple Threads to access a value
Similar Threads
Servlet return value: JQuery Ajax request
"Synchronized" Doubt
Objective 7.1 - Thread Safety and Sesion Object
Static method
What is best use of volatile keyword?