Declare a volatile attribute.
public
|
The volatile keyword is a modifier that ensures an attribute’s value is consistently read the same across all threads.
Ordinarily, an attribute’s value may be written to a thread’s local cache and not immediately updated in main memory, causing other threads to see a different value. The volatile
keyword ensures that threads always update and read the attribute’s value directly from main memory.