• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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: 22524
109
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!