From the course: Advanced Java: Threads and Concurrency
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Synchronization: Purpose and use - Java Tutorial
From the course: Advanced Java: Threads and Concurrency
Synchronization: Purpose and use
- [Narrator] When thread share data issues like data races and race conditions could possibly occur. Though data racers can sometimes cause race conditions. The two are not dependent on each other. For instance, your code could be a possible candidate for a data race to occur, but it might not necessarily lead to a race condition. Or it could perhaps be the other way around. Using the volatile keyword on variables that are shared by multiple threads could help prevent or reduce data races to some extent. It guarantees visibility by always reading from and writing to variable values from and to the main memory and not the CPU registers. This prevents threads from accessing shared data. However, this visibility guarantee is not sufficient when threads that share a piece of data are not just reading it, but also writing it. This is because volatile does not lock the shared piece of data or variable from being read or written to by one thread, from being read or written to by other…
Contents
-
-
-
Memory access in Java threads and its problems5m 43s
-
(Locked)
Memory inconsistency: Data race5m 40s
-
(Locked)
Thread interference: Race condition5m 38s
-
(Locked)
Synchronization: Purpose and use3m 53s
-
(Locked)
Implementing synchronization3m 15s
-
(Locked)
Challenge: Inventory manager2m 45s
-
(Locked)
Solution: Inventory manager4m 50s
-
-
-
-
-
-
-
-