Deadlock defintion
Deadlock is a situation that can occur when two or more threads are blocked indefinitely trying to obtain access to a resource locked by the other threads in the deadlock. Thus, the deadlocked threads are blocked, waiting for each other to release a resource which neither of them can release because they are blocked waiting for the other thread to release its resource first.
Such resources can be Java Locks, Java synchronized blocks (Java monitor objects), files, database tables and / or records etc.

Deadlock code example using two Lock instances in Java
실행결과 - unlock 안함 (그림의 상황)
Deadlock code example using two synchronized blocks in Java
- 여기도 데드락 걸림
Deadlock can occur with any mutually exclusive access / lockable resource
- 데드락은 여러 쓰레드가 접근해서 락을 거는 어떠한 리소스에도 터질 수 있다.
Deadlock fix via lock ordering
- lock 접근 순서를 둘다 lock1, lock2로 함 → 데드락 안걸림
More complex deadlock scenario

e.g. DB 테이블 락, 파일 락 등등
A deadlock will block all threads trying to lock a resource involved in the deadlock

- 데드락에 접근하는 새로운 쓰레드들은 block된다.
The four conditions required for a deadlock to occur
- Mutual Exclusion
- No Preemption
- Hold and Wait
- Circular Wait
Other problems similar to deadlock
- Livelock
- Nested Moniter Lockout
- Reentrance lockout
- Starvation