I just need a confirmation that i have understood the concept of locks in synchronized blocks correctly. First I will tell what I have understood. Acquiring a lock of an object means that no other thread can access the synchronized code of the object's class. In case of synchronized methods, Threads acquire lock on the object used to invoke the method(i.e., implicitly the this reference). That means the other threads cannot access the synchronized code of the class of the current object. But, in case of synchronized blocks we can specify the object on which we want the thread to acquire the lock.
Now lets say we have synchronized block in a method in class A acquiring a lock on object of class B. So lets say one thread enters this synchronized block and has acquired the lock of a particular object of class B.
If any other thread uses the same object of class B it will not be able to enter the synchronized block in class A, right? And also the other threads cannot also access any synchronized code in class B?
And what about the other synchronized code in class A? Because the thread has acquired lock on the object of class B, the other threads can access the other synchronized code of class A or not? This means there is no lock on the object of class A as such, only class B?
I hope people understand my questions.
Thanks in advance.