How to determine the maximum stack size limit?

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?


使用ManagementFactory.getRuntimeMXBean().getInputArguments()来访问传递给VM的所有参数。


也许不是最佳实践,但肯定是直截了当的:我会写一个递归方法计算一个值,直到java.lang.StackOverflowError重复并查看计数器。

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);

}
}
链接地址: http://www.djcxy.com/p/54844.html

上一篇: Visual Studio:进入程序集

下一篇: 如何确定最大堆栈大小限制?