I have an application that will fail if the -Xss
stack size will fail with a StackOverflow
error if the value is set below 256k
. This is unfortunately a case related to a library com.sun.org.apache.xerces
when instantiating a very large XSD validator.
Right now, the pre-defined value for -Xss192k
is what we have been using in certain environments, and know that this is causing the problem.
For logging purposes, I was wondering if it was possible to get the max stack size through Java itself, and throw an error on initialization indicating that the provided stack size is insufficient, rather than having the application deploy, then attempt to utilize the stack for this process, and overflow as a result?
The current StackOverflowError
in the logs is relatively uninformative for debugging purposes, and I know it is bad programming etiquette to catch an error.
Specifically, what I am trying to do is, in pseudocode:
if(jvm.getMaxStackSize() < "256k") {
throw new Exception("Insufficient Stack Size for this application. Please set to 256k or more.");
} //stop program from continuing because the stack size will result in a stackoverflow if set too low
Related post Can one obtain actual stack size used by a thread in Java after some time of running? provides info on how to monitor the stack size at run-time, but I don't see a method to get the JVM's pre-set stack size.