• Post Reply Bookmark Topic Watch Topic
  • New Topic

instance synchronize and static synchronize

 
Yingie Pitts
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's the difference between instance synchronize and static synchronize?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you synchronize instance methods, then if two threads try to call such a method on the same object, then only one will succeed, while the other must wait; if the two threads call synchronized methods on two different objects of the same class, however, then they both succeed.
If we're talking about static methods, then it's always as if the two threads are calling the method on the same object; only one can enter the method at a time.
 
Pierre Henry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- synchronization on Object is trying to acquire a lock on an instance of
the object before executing the sync method
- as a method tries to acquire the lock on the object representing the Class
It is used generally to sync on a static variable of that particular class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!