I am trying to find out if the code below contains any potential concurrency problems. In particular, the visibility problem associated with volatile variables. Volatility is defined as: The value of this variable will never be cached by the thread-locally: all reads and writes will go directly to the "main memory"
public static void main(String [] args) { Test test = new Test();
For the above single-threaded artist :
Is it possible to make test.state unstable? In other words, will there be every subsequent Test.run () (which will happen sequentially, and not simultaneously, because again the executor is a single thread), do you always see the updated value of test.state? If not, will Test.run () exit so that any changes made on the local network are written to main memory? Otherwise, when changes made to the stream locally are written to main memory, if not when exiting the stream?
java multithreading concurrency volatile
Integer
source share