• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronize keyword

 
Joel Bijapurkar
Greenhorn
Posts: 20
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose i synchronize a instance method in a class and create two objects A and B of the same class. Now when object A is accessing the synchronized method will B also be able to access it or will it have to wait until A releases the lock?
 
Matthew Brown
Bartender
Posts: 4566
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They lock different objects (the instance in question), so the methods will be able to run at the same time.

If you synchronized a static method, that locks the class object, and so then any call can block any other.
 
Joel Bijapurkar
Greenhorn
Posts: 20
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Matthew.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic