Concurrency Quote by Brian Goetz
““Locking can guarantee both visibility and atomicity; volatile variables can only guarantee visibility.””
About This Quote
Source Book: Java Concurrency in Practice, 2006
The statement explains that using lock constructs ensures both that changes are seen by other threads and that operations happen indivisibly, whereas volatile only ensures visibility, not atomicity.
In simple terms: Locks give visibility and atomicity; volatile gives only visibility.
Use locks when you need both safety and visibility.
Themes
Mood
Type
When to use this quote
- multithreaded programming
- shared data structures
- performance optimization
Key Concepts
Questions to Reflect On
- When is volatile sufficient?
- How to minimize lock contention?
Locks can cause contention and reduce scalability.