Explore a livelock scenario between two threads with an example Java program in this video. Learn how to resolve the livelock condition by implementing a random selection algorithm to choose which thread has priority to go first.
- [Instructor] To demonstrate a livelock in Java, … I'll modify the dining philosophers example from earlier … that I used to demonstrate a deadlock. … Now, I have not implemented a strategy … to prevent the deadlock in this version, … so if I run this program, … sure enough, after a few iterations, it hits a deadlock. … The philosophers have acquired their first chopstick lock, … and they're stuck waiting for their second one … to become available. … One possible way to fix this problem … would be to have the philosophers release their lock … on their first chopstick … if their second chopstick is not available … when they try to take it. … That will give another philosopher a chance … to take that first chopstick … and hopefully prevent the deadlock. … To implement that, instead of using the regular lock method, … on the second chopstick, I'll use the TryLock method on it. … And, I'll put that in an if statement … that will execute if the lock was not taken. … If that happens, I'll print a message …
- Parallel vs. sequential computing
- Shared vs. distributed memory
- Execution scheduling
- Thread lifecycle
- Mutual exclusion
- Synchronized methods
- Checking for liveness
Skill Level Advanced
Java Essential Training: Objects and APIswith David Gassner2h 46m Intermediate
Java Essential Training: Syntax and Structurewith David Gassner3h 9m Intermediate
1. Parallel Computing Hardware
2. Threads and Processes
3. Mutual Exclusion
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.