In this video, explore a use case for a reentrant mutex when locks are nested by modifying the previous example Java program to demonstrate mutual exclusion. Discover that Java's ReentrantLock can be acquired multiple times by the same thread.
- [Instructor] To demonstrate the try lock method in Java, … I've created this example that simulates … two shoppers searching for the items they need … and then adding to a shared notepad. … In this shopper class, each shopper has their own … instance variable on line nine for the number … of items they need to add to the notepad, … which is how many items they found in a coupon book … or perhaps missing from the fridge. … The static integer on line 10 represents the number … of items they've added to the shared notepad, … and the pencil on line 11 is the lock … that's used to protect access to it. … Down in the run method, the while loop on line 18 … will keep the shoppers searching for items … and adding them to the shared notepad … until there are at least 20 items. … If the shopper has items to add to the notepad, … they'll execute the if clause on line 19, … in which they lock the pencil, add all of their items … to the list, and then print a message … with how many items they added. …
- 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.