This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Synchronize keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Synchronize keyword" Watch "Synchronize keyword" New topic

Synchronize keyword

Joel Bijapurkar

Joined: Aug 01, 2011
Posts: 20

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

Joined: Apr 06, 2010
Posts: 4541

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

Joined: Aug 01, 2011
Posts: 20

Thanks Matthew.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Synchronize keyword
jQuery in Action, 3rd edition