I set Thread stackSize=1, Then invoke three method. In my opinion, method stack is 3 or more. but why not occur Stackoverflow Exception? this is my code:
public class ExecutorsTest {
private static void printOne() {
System.out.println("do Print One");
printTwo();
}
private static void printTwo() {
System.out.println("do Print Two");
printThree();
}
private static void printThree() {
System.out.println("do Print Three");
}
public static void main(String[] args) throws Exception {
ThreadGroup group = new ThreadGroup("thread-Group");
Thread thread = new Thread(group, ()-> {
printOne();
},"myThread",1);
thread.start();
}
}
Each Java Virtual Machine thread has a private Java Virtual Machine stack, created at the same time as the thread.
A Java Virtual Machine stack stores frames. The stack holds local variables and partial results, and plays a part in method invocation and return.
The stack size is the approximate number of bytes of address space that the virtual machine is to allocate for this thread's stack.
The effect of the
stackSize
parameter, if any, is highly platform dependent.
On some platforms, specifying a higher value for the stackSize
parameter may allow a thread to achieve greater recursion depth before throwing a StackOverflowError
.
Similarly, specifying a lower value may allow a greater number of threads to exist concurrently without throwing an OutOfMemoryError
(or other internal error).
The details of the relationship between the value of the stackSize
parameter and the maximum recursion depth and concurrency level are platform-dependent.
On some platforms, the value of the stackSize
parameter may have no effect whatsoever.