In this video, learn about how Java's synchronized keyword can be used to enforce mutual exclusion on methods with an example Java program.
- [Instructor] Something unique in Java is that every object … has an intrinsic lock associated with it, … a thread that needs exclusive access to an object's fields … has to acquire that object's lock before accessing them … and then release that intrinsic lock when it's done. … The Java programming language … provides two basic synchronization constructs … to use those intrinsic locks, … synchronized methods and synchronized statements. … To make a synchronized method in Java, … simply add the keyword synchronized … to the method's declaration. … When a thread invokes a synchronized method, … it automatically acquires the intrinsic lock … for that method's object. … That will prevent other threads … that invoke a synchronized method on the same object … from interleaving execution. … When a thread tries to invoke a synchronized method … while another thread is executing a synchronized method … for that same object, … the second thread will suspend execution … until the first thread is done and exits. …
- 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.