Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid the 1024 lines of Java exception stack limit

Tags:

java

I ran into a Java StackOverflow error, but the offending recursive call is so deep, that it does not give me the full stack trace. It only dumps out the first 1024 lines of methods of the StackOverflow exception.

How can I get the full stack trace, so that I can know the root cause?

like image 678
Jeff Avatar asked Aug 05 '10 18:08

Jeff


People also ask

Can we handle stack overflow error?

Stack overflow means, that you have no room to store local variables and return adresses. If your jvm does some form of compiling, you have the stackoverflow in the jvm as well and that means, you can't handle it or catch it.

What is the limit of stack in Java?

The Java stack size is the size limit of each Java thread in the Java Virtual Machine (JVM) that runs the monitoring Model Repository Service. The default value is 512K.

How does Java handle stack overflow?

Increase Thread Stack Size (-Xss) Increasing the stack size can be useful, for example, when the program involves calling a large number of methods or using lots of local variables. This will set the thread's stack size to 4 mb which should prevent the JVM from throwing a java.


1 Answers

The switch -XX:MaxJavaStackTraceDepth allows larger and smaller stack trace lengths. Set it to -1 for an unlimited length. E.g.:

-XX:MaxJavaStackTraceDepth=-1
like image 154
Dan Gravell Avatar answered Sep 24 '22 00:09

Dan Gravell