Suppose there are 2 classes, Parent class and Child class which extends Parent class. Now and both have two method which are synchronized.My question which object lock will be use for locking this synchronized methods i create object like : Parent p=new Child(); Is is parent object lock or Child object lock?
There is no parent object lock or child object lock. There is only one lock, the object's. In this case, it will be p's.
Threads will block when entering a parent's synchronized method if another thread has the lock in a child's synchronized method, and vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With