What is DeadLock?
if two thread executing on two different objects.
Let's assume thread t1,t2 and objects ob1 ,ob2
t1 got the lock of object ob1.
t2 got the lock of object ob2.
let's assume the situation when t1 wanna execute method which is present in ob2(t2 has a lock on ob2) and t2 wanna execute method which is present in ob1(t1 has a lock on ob1).
Note-Both methods are synchronized.
Thread t1 asked t2 to release the lock of object ob2. So that t1 can execute the method present in ob2. But t2 disagree to release the lock of object ob2 and t2 asked t1 the same thing what t1 has asked for t2 to do.t1 also disagrees with t2.
Both threads not to release lock is simple stubbornness(zidd in Hindi).
This is the only reason for infinite waiting which is called deadlock.
- If two thread is waiting for each other forever. Such type of infinite waiting is called DeadLock.
- Synchronized Keyword is the only reason for the DeadLock situation while using it we have to take special care.

Comments
Post a Comment