Use volatile only for visibility
volatile makes updates visible across threads but does not make compound operations such as count++ atomic. Use AtomicInteger or locking when an operation must be indivisible.
Appreciate the write-up on "Use volatile only for visibility". Useful for anyone using java / threads.
Good to see "Use volatile only for visibility" written down. Handy reference for anyone working with java / threads.
Good to see "Use volatile only for visibility" written down. Handy reference for anyone working with java / threads.
Per JLS 17.7,
volatile longanddoublereads and writes are atomic, but plain 64-bit fields are not guaranteed atomic. Corrections or other cases welcome below.Clear note on java / threads. "Use volatile only for visibility" is the kind of detail that is easy to overlook.
Clear note on java / threads. "Use volatile only for visibility" is the kind of detail that is easy to overlook.
Appreciate the write-up on "Use volatile only for visibility". Useful for anyone using java / threads.
Good to see "Use volatile only for visibility" written down. Handy reference for anyone working with java / threads.
Appreciate the write-up on "Use volatile only for visibility". Useful for anyone using java / threads.