"call stack" 和 "thread stack" 之间的区别

Difference between "call stack" and "thread stack"

在 Java 多线程中,术语 call stackthread stack 之间是否存在语义差异?

每个线程都有自己的调用栈,“调用栈”和“线程栈”是一回事。称它为“线程堆栈”只是强调调用堆栈是特定于线程的。

Bill Venners calls this the Java stack:

When a new thread is launched, the Java virtual machine creates a new Java stack for the thread. As mentioned earlier, a Java stack stores a thread's state in discrete frames. The Java virtual machine only performs two operations directly on Java Stacks: it pushes and pops frames.

The method that is currently being executed by a thread is the thread's current method. The stack frame for the current method is the current frame. The class in which the current method is defined is called the current class, and the current class's constant pool is the current constant pool. As it executes a method, the Java virtual machine keeps track of the current class and current constant pool. When the virtual machine encounters instructions that operate on data stored in the stack frame, it performs those operations on the current frame.

When a thread invokes a Java method, the virtual machine creates and pushes a new frame onto the thread's Java stack. This new frame then becomes the current frame. As the method executes, it uses the frame to store parameters, local variables, intermediate computations, and other data.

A call stack 是一个 stack data structure,它存储有关计算机程序的活动子例程的信息。

你所说的 thread stack 我认为是线程的私有堆栈。

这两个东西本质上是一样的。他们都是stack data structures.

A thread's stack is used to store the location of function calls in order to allow return statements to return to the correct location

由于通常只有一个重要的调用栈,也就是人们所说的

Here是关于堆栈的信息。

Here是关于Stack-based内存分配的信息。

每个线程都有自己的堆栈,每个方法调用都使用该堆栈的一个新区域。这意味着当一个方法调用自身(递归)时,它将有一组新的局部变量。

FileWriter抛出IOException时,运行时系统立即停止执行try块;正在执行的方法调用未完成。然后,运行时系统开始在方法调用堆栈的顶部搜索合适的异常处理程序。
在此示例中,当 IOException 发生时,FileWriter 构造函数位于调用堆栈的顶部。但是,FileWriter 构造函数没有合适的异常处理程序,因此运行时系统会检查方法调用堆栈中的下一个方法——writeList 方法。 writeList 方法有两个异常处理程序:一个用于 IOException,一个用于 IndexOutOfBoundsException.