jQuery in Action, 2nd edition
The moose likes Threads and Synchronization and the fly likes Local variables (including local class variables) specified inside a method is thread safe. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Local variables (including local class variables) specified inside a method is thread safe. " Watch "Local variables (including local class variables) specified inside a method is thread safe. " New topic
Author

Local variables (including local class variables) specified inside a method is thread safe.

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Local variables (including local class variables) specified inside a method is thread safe. Then why Synchronized is used on method?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

jacob deiter wrote:Local variables (including local class variables) specified inside a method is thread safe. Then why Synchronized is used on method?


First, what the heck is a "local class variable"?

But to answer your question, what about local reference variables that reference something that is shared? Maybe passed in via parameter to the method? The local reference may be threadsafe, but the object may not be.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Local variables (including local class variables) specified inside a method is thread safe.
 
Similar Threads
Vector as a local variable
threads and collections
Regarding SingleThreadModel from J@Whiz
Thread Safety Question?
Are Local variables Thread Safe?