Explore a use case for a reentrant mutex when locks are nested by modifying the previous example Java program to demonstrate mutual exclusion in this video. Discover that Java's ReentrantLock can be acquired multiple times by the same thread.
- [Instructor] In Java, there are three classes … that implement the lock interface, … a basic reentrant lock and two types … of reentrant read write locks for reading and writing … which we'll cover later. … Notice that all three of those … have the word reentrant in their name, … and that's because Java does not have a standard … non-reentrant lock. … So for this video, I won't be able to compare … a non-reentrant and a reentrant lock, … so I'll just be using a reentrant lock … to demonstrate its behavior. … This is a variation of the previous example … I used to demonstrate a data race … and implementing mutual exclusion, … with two shopper threads that concurrently increment … the amount of items to buy on a shared shopping list. … In this version, the shopper class has a private method … on line 12 called addGarlic which uses the reentrant lock … named Pencil to enforce mutual exclusion … around a call to increment the class variable … named Garlic on line 14. … A related method on line 18 named addPotato …
- 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.