package com.dic.stack;
/**
*/
public class JavaVMStackSOF {
private int stackLength = 1;
public void stackLeak() {
stackLength++;
if(stackLength==10800) return;
stackLeak();
}
public static void main(String[] args) throws Throwable {
JavaVMStackSOF oom = new JavaVMStackSOF();
for(String name:System.getenv().keySet()){
System.out.println(name+":"+System.getenv(name));
}
Runtime runTime=Runtime.getRuntime();
//runTime.addShutdownHook(hook);
try {
oom.stackLeak();
} catch (Throwable throwable) {
System.out.println(oom.stackLength);
throw throwable;
}
}
/**
* VM args -Xss160k 栈大小 决定栈的深度 set java thread stack size
**/
public class JavaVMStackSOF {
private int stackLength = 1;
public void stackLeak() {
stackLength++;
if(stackLength==10800) return;
stackLeak();
}
public static void main(String[] args) throws Throwable {
JavaVMStackSOF oom = new JavaVMStackSOF();
for(String name:System.getenv().keySet()){
System.out.println(name+":"+System.getenv(name));
}
Runtime runTime=Runtime.getRuntime();
//runTime.addShutdownHook(hook);
try {
oom.stackLeak();
} catch (Throwable throwable) {
System.out.println(oom.stackLength);
throw throwable;
}
}
}
可以设置一下这个参数,看看stack 什么时候溢出