Why is the code below not deadlocking? I mean, after calling getNumber (.), The object of the Test class should be locked, so I should not have access to getNumber2 (.).
class Test() {
synchronized int getNumber(int i){
return getNumber2(i);
}
synchronized int getNumber2(int i) {
return i;
}
public static void main(String[] args) {
System.out.println((new Test()).getNumber(100));
}
}
Conclusion:
100
source
share