How to determine the maximum stack size limit?

穿精又带淫゛_ 提交于 2019-12-22 04:59:13

问题


I want to determine the maximum size of the stack programmatically from within Java (the size set by -Xss). How do I do this?

Alternatively, as my Java module also uses a native code module, I would be able to do this via JNI; but how?


回答1:


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




回答2:


Maybe not best practice but certainly straight-forward: I'd write a recursive method counting up a value, recurring until java.lang.StackOverflowError and look 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);

}
}


来源:https://stackoverflow.com/questions/7487767/how-to-determine-the-maximum-stack-size-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!