我正在阅读关于 Internal Java Memory Model 的文章. 有一点想问一下:
Each thread running in the Java virtual machine has its own thread stack. The thread stack contains information about what methods the thread has called to reach the current point of execution.
为什么每个线程都需要保存有关已执行哪些方法的信息(!)?如果它与上下文切换有关,那么(如果我没记错的话)线程必须保存有关当前正在执行的方法的信息。 实际需要保存已执行方法的信息是什么?
最佳答案
这是指当前活跃的方法。请注意,线程中可以同时激活多个方法(A 调用 B 调用 C,...)。堆栈不包含有关已完成方法的信息。
关于java - 线程堆栈的内部 Java 内存模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54862051/