When not to use volatile variable in Java

Viewed 703

I understand the volatile variables only guarantee visibility and should not be used for atomic/compound operations. However I think I read some where that it can also be used only if one thread is updating the value (in a single operation). Is this correct ?

So if two threads are updating a volatile variable say boolean flag is this thread safe ?

1 Answers
Related