Yes, or something that has the same guarantees, such as accessing inside a synchronized block (on both threads, on the same lock!) or getting more complicated, the various other locks and atomic things in java.util.concurrent
(eg. there is an AtomicBoolean that can atomically compare and set)
If you have a situation where two threads are reading / writing to the same variable and each thread doesn’t care about the other, you probably shouldn’t be using a shared variable in the first place!