Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
jacob deiter
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Local variables (including local class variables) specified inside a method is thread safe. Then why Synchronized is used on method?
 
Henry Wong
author
Sheriff
Posts: 22827
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!