This week's book giveaway is in the Java in General forum. We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line! See this thread for details.
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?
posted 4 years ago
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.