posted 20 years ago
This is from Max book. Faq on Threading page no 137.
Q: What happens when one method synchronizes on a member method, and another
synchronizes on this memeber variable, and two have to inertact :
A: Then you are acquring two locks on tho distinct objects-namly this and the member variable, and it is very important to be careful. Otherwise, you are openeing the door to deadlock.
My question :
I have two cases below, i could not understand, is it case(given below) 1 or 2?
case 1:
public class TestCase1{
//some instance variables
public synchronize void methodA(){
// some code
}
public void methodB(){
synchronize(this){
//some code
}
//some code
}
}
case 2:
public class TestB{
private Vector container;
public void methodA(){
synchronize(container){
// some code
}
//some code
}
public void methodB(){
synchronize(this){
//some code
}
//some code
}
Or, some other case which i am missing.
Regards,
Akash.