Created Saturday 07 September 2013
- the value of the variable is always stored in the JavaMemory:HeapSpace and not in the stack
- a write to volatile variable establishes a happens-before relationship with readers. All readers will see the new value of the variable once the writer finishes.
When to Use Volatile
- To make long and doubles atomic
- Alternative way of doing synchronization
- To tell compiler to NOT do code optimization that is undesirable in multi-threaded environment. Ex: don't cache value in stack
No backlinks to this page. comments powered by Disqus