标签:void cat 操作 ted 计数 cep [] 方法区 star
1 /** 2 * java栈溢出StackOverFlowError 3 * JVM参数:-Xss128k 4 * Created by chenjunyi on 2018/4/25. 5 */ 6 public class JavaVMStackSOF { 7 8 private int stackLength = -1; 9 10 //通过递归调用造成StackOverFlowError 11 public void stackLeak() { 12 stackLength++; 13 stackLeak(); 14 } 15 16 public static void main(String[] args) { 17 JavaVMStackSOF oom = new JavaVMStackSOF(); 18 try { 19 oom.stackLeak(); 20 } catch (Throwable e) { 21 System.out.println("Stack length:" + oom.stackLength); 22 e.printStackTrace(); 23 } 24 } 25 26 }
1 Stack length:983 2 java.lang.StackOverflowError 3 at com.manayi.study.jvm.chapter2._02_JavaVMStackSOF.stackLeak(_02_JavaVMStackSOF.java:14) 4 at com.manayi.study.jvm.chapter2._02_JavaVMStackSOF.stackLeak(_02_JavaVMStackSOF.java:15) 5 at com.manayi.study.jvm.chapter2._02_JavaVMStackSOF.stackLeak(_02_JavaVMStackSOF.java:15) 6 ······
1 ** 2 * java栈溢出OutOfMemoryError 3 * JVM参数:-Xss2m 4 * Created by chenjunyi on 2018/4/25. 5 */ 6 public class JavaVMStackOOM { 7 8 private void dontStop() { 9 while (true) { 10 } 11 } 12 13 //通过不断的创建新的线程使Stack内存耗尽 14 public void stackLeakByThread() { 15 while (true) { 16 Thread thread = new Thread(() -> dontStop()); 17 thread.start(); 18 } 19 } 20 21 public static void main(String[] args) { 22 JavaVMStackOOM oom = new _03_JavaVMStackOOM(); 23 oom.stackLeakByThread(); 24 } 25 26 }
1 Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
标签:void cat 操作 ted 计数 cep [] 方法区 star
原文地址:https://www.cnblogs.com/manayi/p/9293302.html