java - Why deadlock is not happening for implicit locks? -
what re-entrant lock , concept in general? says
if lock non re-entrant grab lock, block when go grab again, deadlocking 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 , executed
implicitlock lock1 = new implicitlock(); lock1.test1();
i got below output though expecting deadlock when call goes test2 per implicit lock description didn't
enter test1 inside test2 exit test1
java synchronized lock reentrant. jakob jenkov blog:
lock reentrance
synchronized blocks in java reentrant. means, if java thread enters synchronized block of code, , thereby take lock on monitor object block synchronized on, thread can enter other java code blocks synchronized on same monitor object. here example:
public class reentrant{ public synchronized outer(){ inner(); } public synchronized inner(){ //do } }
taken from: http://tutorials.jenkov.com/java-concurrency/locks.html
Comments
Post a Comment