Multithreading - Concurrent Programming (3) - Memory Layout of Multithreading

PC register (Program Counter Register) : each thread has its own PC register

Java Virtual Machine Stack (Java Virtual Machine Stack) : Each thread has its own Java virtual machine stack
understanding: the stack is first-in, last-out; if each thread does not have its own Java virtual machine stack, then return and arrange There is a problem with the above, because the thread will rush in to execute the conflict

例:static void main1(){
   test1();
}
static void test1(){

}
static void main2(){
   test2();
}
static void test2(){
   
}
//如果无各自的Java 虚拟机栈的话便会如下发布发生乱套
// test2()
// test1()
// main2()  *抢进来了*
// main1()

Native Method Stack : Each thread has its own native method stack
//The reason is basically the same as the virtual machine stack

Heap : The heap is shared by multiple threads

Method Area : Multiple threads share the method area
 

Guess you like

Origin blog.csdn.net/weixin_59624686/article/details/123964023