Java memory model
Main memory vs. working memory
The Java memory model specifies that all variables are stored in main memory (where the main memory is analogous to the main memory name of the physical computer, but this is only part of the virtual machine memory), where variables include instance fields , static fields and elements that make up an array object , but do not include local variables and method parameters , because the latter is thread-private. Each thread also has its own working memory (which can be likened to the processor's cache), where the thread's working memory holds a copy of the master memory of the variable used by the thread, and all operations of the thread on the variable (read and write, etc.) must be in working memory and cannot be read directly to the variables in main memory. There is no direct access to variables in the other's working memory between different threads, and the transfer of variable values between threads must be done through main memory. The interaction between threads, main memory, and working memory
Java memory model