一、JMM
- 所有的共享变量都存储在主内存。
Memory that can be shared between threads is called shared memory or heap memory.
All instance fields, static fields, and array elements are stored in heap memory. In this chapter, we use the term variable to refer to both fields and array elements.
Local variables, formal method parameters, and exception handler parameters are never shared between threads and are unaffected by the memory model. - 每个线程都会有自己的working memory。保留了被线程使用的变量的副本。rate:CPU>working memory>主存。working memory是为了缓解CPU和主存速度不匹配的一钟折中解决方法。
- 线程对变量的所有操作(读/写)都必须在working memory中完成,而不能直接读写主存中的变量。
- 不同线程之间也不能直接访问对象working memory中的变量,线程间变量的值需要通过主内存中转来完成。
working memory:Every thread is defined to have a working memory (an abstraction of caches and registers) in which to store values.