Public Class A
{
private Object memberlockObject = new Object();
public doStuffapproach1(){
synchronized(this){
// Do something;
}
}
public doStuffapproach2(){
synchronized(memberlockObject){
// Do something;
}
}
public doStuffapproach3(Object parameterLockObject){
synchronized(parameterLockObject){
// Do something;
}
}
}
In the above code, do the methods doStuffapproach1, doStuffapproach2, doStuffapproach3 achieve the same type of block synchronization or not. If not, how do they differ from each other. In what scenarios should each be used ?
P.S : I understand that method level synchronization is as good as synchronizing whole method body on (this).