本文主要是介绍Java 测试Thread StackOverflowError,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
测试堆栈溢出
@Testpublic void testStackOverflow() {try {foo1();} catch (Throwable throwable) {// 栈满时,打印递归深度System.out.println(countRecursion);throw throwable;}}public void foo1() {++countRecursion;foo1();}
- JVM option
- Xmx50m
- Xss20m
线程栈大小默认下与堆内存相关,可直接给值
总 -Xmx50m -Xss20m
输出如下:
1112405java.lang.StackOverflowErrorat org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)
作为对比,不设置Xss
11356java.lang.StackOverflowErrorat org.test.learn.jvm.JVMProf.foo1(JVMProf.java:55)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)at org.test.learn.jvm.JVMProf.foo1(JVMProf.java:56)
这篇关于Java 测试Thread StackOverflowError的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!