MENU

Fun & Interesting

Deadlock in Java

Jakob Jenkov 25,495 4 years ago
Video Not Working? Fix It Now

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. Chapters: 0:00 Deadlock defintion 1:04 Deadlock code example using two Lock instances in Java 5:43 Deadlock code example using two synchronized blocks in Java 7:19 Deadlock can occur with any mutually exclusive access / lockable resource 7:57 Deadlock fix via lock ordering 8:54 More complex deadlock scenario 11:14 A deadlock will block all threads trying to lock a resource involved in the deadlock 12:50 The four conditions required for a deadlock to occur 15:44 Other problems similar to deadlock Deadlock in Java - text: http://tutorials.jenkov.com/java-concurrency/deadlock.html Deadlock Prevention in Java - video: https://www.youtube.com/watch?v=3cgZbACBpxI&list=PLL8woMHwr36EDxjUoCzboZjedsnhLP1j4&index=14 Java Concurrency Tutorial - text / video http://tutorials.jenkov.com/java-concurrency/index.html https://www.youtube.com/playlist?list=PLL8woMHwr36EDxjUoCzboZjedsnhLP1j4 Starvation and Fairness - text: http://tutorials.jenkov.com/java-concurrency/starvation-and-fairness.html Nested Monitor Lockout - text: http://tutorials.jenkov.com/java-concurrency/nested-monitor-lockout.html Reentrance Lockout - text: http://tutorials.jenkov.com/java-concurrency/reentrance-lockout.html Java Lock - text / video http://tutorials.jenkov.com/java-util-concurrent/lock.html https://www.youtube.com/watch?v=MWlqrLiscjQ&list=PLL8woMHwr36EDxjUoCzboZjedsnhLP1j4&index=11

Comment