Learn about the special atomic data types in Java in this video. Discover that the lock and counter in the previous example Java program can be replaced with an AtomicInteger to achieve the same result.
- [Instructor] Using a lock to protect a shared variable … with mutual exclusion works, … but if you're only doing simple operations … like incrementing the variables value, … then a simpler way to do that in Java is … by using the Atomic package. … It provides a collection of classes … that support lock-free, thread safe programming … on single variables. … If I scroll down on the documentation page, … I see a variety of classes I can choose from … including Atomic booleans, integers, arrays, … long values, references, and so on. … I'll select the Atomic integer class, and if I scroll down, … I can see that it has a variety … of methods that implement Atomic versions … of most standard integer operations. … To demonstrate using Atomic variables in Java, … I'm going to modify the previous example code … that I used to demonstrate a data race. … It has two parallel threads incrementing … a count variable 10 millions times each. … I should get an output of 20 million, … but since I'm just using a regular integer on line seven, …
- 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.