Java多线程的工作内存是什么?
PHP中文网
PHP中文网 2017-04-17 17:41:47
0
4
460

Java的内存模型分为主内存,和工作内存。

主内存是所有的线程所共享的,工作内存是每个线程自己有一个,不是共享的。

线程工作时将要用到的变量从主内存拷贝到自己的工作内存,然后在工作内存中进行读和写。

写完之后,可能没被更新到主内存去。导致其他线程从主内存拷贝数据到自己的工作区时,拷贝的不是最新的数据。这就是内存可见性问题。

那么问题来了,Java的工作内存是什么??

百度 "java多线的工作内存是什么“,看了很多博客都说是各种缓存。

但是缓存不是大家都能访问的吗?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(4)
Ty80

The definition of cache here is too broad and can easily cause ambiguity. Liz, just look at this

Peter_Zhu
  1. The Java virtual machine specification defines the Java memory model to shield the memory differences of various hardware and operating systems to achieve cross-platform memory access effects.

  2. In order to obtain better execution performance, the Java memory model does not limit the execution engine to use the processor's specific cache or cache to interact with main memory (which can be compared to RAM, but is part of the virtual machine memory), working memory (which can be The analog cache, which is also part of the virtual machine's memory) is private to the thread.

  3. The division of working memory and main memory is different from the division of Java heap, stack, and method area. The two are basically irrelevant. If they barely correspond, the main memory can be understood as the instance data part in the heap, and the working memory corresponds to the part in the stack Area

-----Quote<<In-depth understanding of JAVA virtual machine>>

Peter_Zhu

A thread will have a thread stack, and a method call is a stack frame. A stack frame is divided into: local variable area, operand stack and frame data area.
You can understand that working memory is the data in the local variable area.

大家讲道理

@wlingxiao said in "In-depth Understanding of JAVA Virtual Machine", Second Edition, 12.3.1 Main Memory and Working Memory

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template