I grabbed the concept of synchronization as the following: every object in Java has a monitor and a lock. Lock is an entity which can be acquired or released by a thread, whereas monitor is an instance's mechanism which decides whether or not a thread can get the lock on an object.
I'd like to clarify the following example. Firstly, I want to create two objects:
MyClass obj1 = new MyClass();
MyClass obj2 = new MyClass();
Will each instance has its own monitor and lock? Or a shared one?
If I synchronize on a class:
synchronized (MyClass.class) {
...
}
How will it behave? Will this synchronization block acquiring of obj1 and obj2 locks? If so, is there any lock hierarchy in Java?
Follow-up: Which is the correct way to say "the object's monitor" or "the object's lock"?