Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding static method

 
rai talari
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Static method is synchronized which object is considered for lock?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instance of java.lang.Class associated with the class in which the method resides.
 
Raghu Arikeri
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
just want add something to what Peter Chase said...

For every class loaded, the JVM has a corresponding java.lang.Class instance. So when a static method is synchronized, it's the lock of java.lang.Class instance which is used.

for instance methods there will be one lock per instance and for static methods one lock per class
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic