What is the Re-entrant lock and concept in general? says
If a lock is non re-entrant you could grab the lock, then block when you go to grab it again, effectively deadlocking your own process.
public class ImplicitLock {
synchronized public void test1() {
System.out.println("enter test1");
test2();
System.out.println("exit test1");
}
synchronized public void test2() {
System.out.println("inside test2");
}
}
From main class , i executed
ImplicitLock lock1 = new ImplicitLock();
lock1.test1();
I got the below output though i was expecting deadlock when call goes for test2 as per SO implicit lock description but it didn't
enter test1
inside test2
exit test1