Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.
Deadlock occurs because:
Mutual exclusion - Two processes cannot simultaneously control the same resource or be in their critical section.
Hold and Wait - processes currently holding resources can request new resources.
No preemption - Once a process holds a resource, it cannot be taken away by another process or the kernel.
Circular wait - Each process is waiting to obtain a resource which is held by another process.
Deadlocks in Java:
Deadlocks can occur in Java when the synchronized keyword causes the executing thread to block while waiting to get the lock, associated with the specified object. Since the thread might already hold locks associated with other objects, two threads could each be waiting for the other to release a lock. In such case, they will end up waiting forever.