What is the volatile keyword useful for?

Technology CommunityCategory: JavaWhat is the volatile keyword useful for?
VietMX Staff asked 3 years ago

volatile has semantics for memory visibility. Basically, the value of a volatile field becomes visible to all readers (other threads in particular) after a write operation completes on it. Without volatile, readers could see some non-updated value.