abstract class Basic (){
public synchronized void basicMethod(String string){
//Some actions here
}
}
public class A extends Basic{
public void aMethod(){
//Some actions here
}
}
public class B extends Basic{
public void bMethod(){
//Some actions here
}
}
Basic a = new A();
Basic b = new B();
a.basicMethod(); // acquires lock
b.basicMethod(); //Same lock?
In other words – lock is related to concrete Object or Super class important too?
Different locks. A
synchronizedinstance method synchronizes on the monitor associated with that particular object instance, so each ofaandbhas its own monitor.If you had
then calls to
a.basicMethod()anda.aMethod()would lock the same monitor.