volatile : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

volatile
The volatile keyword is used on variables that may be modified simultaneously by other threads. This warns the compiler to fetch them fresh each time, rather than caching them in registers. This also inhibits certain optimisations that assume no other thread will change the values unexpectedly. Since other threads cannot see local variables, there is never any need to mark local variables volatile. You need synchronized to coordinate changes to variables from different threads, but often volatile will do just to look at them.

Just What Does volatile Guarantee?

What volatile does is subtle, tying into the rest of the memory model, so there isn’t a simple way to isolate it in this short explanation — but the memory model section in the JLS (Java Language Specification) explains it well. Now that you have read this overview to give you the general idea of what volatile does, you need to read the JLS to understand the fine points.

Learning More



This page is posted
on the web at:

http://mindprod.com/jgloss/volatile.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\volatile.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.145.89.89]
You are visitor number