Volatile guarantees and out-of-order execution [duplicate]
No, you will never get a NPE. This is because volatile also has the memory-effect of introducing a happens-before relationship. In other words, it will prevent reordering of a = one; b = two; The statements above, will not be re-ordered, and all threads will observe value one for a if b already has value … Read more