How to determine the maximum size of the stack size?

I want to determine the maximum stack size programmatically from Java (the size given by -Xss). How to do it?

Alternatively, since my Java module also uses its own code module, I could do this through JNI; but how?

+7
source share
2 answers

Use ManagementFactory.getRuntimeMXBean().getInputArguments() to access all the arguments passed to the VM.

+4
source

Maybe not the best practice, but certainly straightforward: I would write a recursive method that counts a value that repeats until java.lang.StackOverflowError and looks at the counter.

 public class Test { static void recur(AtomicInteger start) { start.incrementAndGet(); recur(start); } public static void main(String[] args) throws ParseException { AtomicInteger start=new AtomicInteger(0); try { recur(start); } catch (java.lang.StackOverflowError e) { /**/ } System.out.println(start); } } 
0
source

All Articles