volatile : Java Glossary

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



CMP homejump to top

available 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
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[54.234.67.55]
You are visitor number 257,433.