Understanding the conditions behind using volatile variable

I came across the following in the book java concurrency in practice :
Frankly speaking i dont understand why all of these conditions are required.
Unable to find any reasons for all this.

Please help me understand it.

Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Volatile means that the var has to be read from main memory so it can *be seen for both reads and writes with equal integrity.

(There's a bit more subtlety to it than that, but a read-up in the literature will explain it in more detail.)

* Sorry - edited typo.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Volatile is a weaker form of synchronisation (volatile variables only guarantee visibility, not atomicity). Variables can be cached in registers or CPU caches and thus can be hidden from other processors. A volatile variable on the other hand is shared by everyone since it is stored in main memory.

The way I understand it, the conditions you read mean that you should use volatile only when

1) atomicity is not a requirement and
2) the volatile variable does not participate in other state variables that calculate a result and
3) you do not need any locking
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.