title: When exactly do you use the volatile keyword in Java?
body: <p>I have read "<a href="http://www.javamex.com/tutorials/synchronization_volatile_when.shtml" rel="noreferrer">When to use 'volatile' in Java?</a>" but I'm still confused. How do I know when I should mark a variable volatile? What if I get it wrong, either omitting a volatile on something that needs it or putting volatile on something that doesn't? What are the rules of thumb when figuring out what variables should be volatile in multithreaded code?</p>