I was studying reentrant locking in Java. Need certain clarification on this concept that how actually it works. What all I understand for below snippet :
class Test{
public synchronized a(){
some code;
b();
some code;
}
public synchronized b(){
some code;
}
}
Above code has this scenario of reentrant lock issue.
What I understand here is, suppose we had Two Threads: T1 and T2 in application executing on Test shared object.
Whoever T1 or T2 acquires lock acquire on both a() and b(). Let say T1 first and executing a(). While execution of a() control reaches to b(); call. Now in that case T1 expecting a new Lock for this b(), or since it already had lock over b() so locking is skipped.
Need help with detailed explanation of this behavior along with issue in above code . Also how reentrant locking mechanism will help here along with snippet and detailed explanation for that as well.