Learn what happens when a thread prematurely terminates while possessing a lock with an example Java program in this video. Also, learn how to resolve the problem by implementing a try/catch/finally clause to guarantee that the lock will always be released.
- [Instructor] To demonstrate what happens … if you abandon a lock in Java, … I'll be modifying a version of the previous … dining philosophers example that I used … to demonstrate a deadlock. … It has three philosophers using chopsticks … to take sushi from a shared plate. … I've already fixed the deadlock in this version, … so if I run this program, … the philosophers successfully take turns … eating sushi until all of the pieces are gone. … The critical section for this program exists … between the lock calls on line 23 and 23, … and the calls to the unlock method … on lines 32 and 33. … Now, if one of the philosopher threads acquires … those locks and then something goes wrong … in the critical section and throws an unexpected error, … that could cause its thread to terminate … before it gets a chance to release those locks. … To simulate that happening, … I'm going to add another if statement … that checks to see if there are exactly … 10 pieces of sushi left. … And if so, I'll use my favorite technique …
- 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.