For Java's memory model, each volatile will keep a copy in the working memory of the thread, but the Java memory model ensures the visibility of variables by adding a special mechanism to volatile variables. The thread must immediately save it to the main memory after modifying the volatile type variable. Before using the variable, it must load the data from the main memory. At the same time, it also performs some operations that prohibit instruction reordering. For the working memory (private memory) of each thread, there are moments when volatile variables are inconsistent, but for the execution engine, the above rules ensure that the variables are consistent.
For Java's memory model, each volatile will keep a copy in the working memory of the thread, but the Java memory model ensures the visibility of variables by adding a special mechanism to volatile variables.
The thread must immediately save it to the main memory after modifying the volatile type variable. Before using the variable, it must load the data from the main memory. At the same time, it also performs some operations that prohibit instruction reordering. For the working memory (private memory) of each thread, there are moments when volatile variables are inconsistent, but for the execution engine, the above rules ensure that the variables are consistent.
No, I recommend a blog
Java concurrent programming volatile keyword analysis