Reading a shared primitive variable in one thread may not yield the value of the latest most recent write to the variable from another thread. It is important to ensure that a read of a shared variable sees the value of the most recent write to the variable. If this is not done, multiple Multiple threads may observe stale values of the shared variable and fail to act accordinglyperform the necessary actions on a timely basis. Visibility of the latest value can be ensured by declaring the variable as volatile
or correctly synchronizing the reads and writes to the variable.
...