Dead lock in Java

Dead lock can happen when two threads tries to lock on Object which is already locked by each other thread. In general terms lets say t1 and t2 threads acquired a locks on lock1 and lock2 respectively.

Now t1 thread trying to lock on lock2 and t2 thread trying to acquire lock on lock1, this leads to a dead lock or this situation can be called as dead lock situation.

Dead example in Java


The above example will lead to a dead lock situation, to check the dead lock you may need to trigger the thread dump for the above program.To Exit from the above program just stop the execution forcefully by killing or in other words


<-PREV NEXT->