that can be modified by another thread but this is not gurranteed. also this is not thread safe either. To make a variable gurranteed to see from another thread you need to do any of the following
Changes to fields made by one thread are guaranteed to be visible to other threads only under the following conditions:
- A writing thread releases a synchronization lock and a reading thread subsequently acquires that same synchronization lock.
- If a field is declared as volatile, any value written to it is flushed and made visible by the writer thread before the writer
thread performs any further memory operation (i.e., for the purposes
at hand it is flushed immediately). Reader threads must reload the
values of volatile fields upon each access.- The first time a thread accesses a field of an object, it sees either the initial value of the field or a value since written by some other thread.
- As a thread terminates, all written variables are flushed to main memory. For example, if one thread synchronizes on the termination of another thread using Thread.join, then it is guaranteed to see the
effects made by that thread (see §4.3.2).
helpful SO thread