-xss128k: This JVM parameter is used to configure the stack size to 128k
Because the stack is thread-private (it is unclear to understand the structure of the JVM virtual machine), the exception is generated if we start a thread and call a recursive in the thread.
/** * VM args:-xss128k * */public class Javavmstacksof {private int stacklength = 1;public void Stackleak () {Stackleng Th++;stackleak ();} public static void Main (string[] args) throws Throwable {javavmstacksof oom = new javavmstacksof (); try {oom.stackleak ();} catch (Throwable e) {System.out.println ("stack length:" + oom.stacklength); throw e;}}}
Analysis:
1. Calling Javavmstacksof's Stackleak () method in the main thread and calling itself in Stackleak ()
2. Each call to itself generates a stack frame at a time (the stack frame is divided into three parts: the local variable area (Variables), the operand stack (Operand stack), and the frame data area), so it takes up a certain amount of space
3. The-xss128k we set up means that the main thread's stack space is only 128k. An oom exception occurs when the stack space is low-Exception in thread "main" Java.lang.StackOverflowError
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Reading notes-in-depth understanding of oom caused by JVM virtual machine -1.jvm-stack