How to increase the Java stack size?

后端 未结 9 1768
余生分开走
余生分开走 2020-11-22 01:59

I asked this question to get to know how to increase the runtime call stack size in the JVM. I\'ve got an answer to this, and I\'ve also got many useful answers and comments

9条回答
  •  孤城傲影
    2020-11-22 02:16

    It is hard to give a sensible solution since you are keen to avoid all sane approaches. Refactoring one line of code is the senible solution.

    Note: Using -Xss sets the stack size of every thread and is a very bad idea.

    Another approach is byte code manipulation to change the code as follows;

    public static long fact(int n) { 
        return n < 2 ? n : n > 127 ? 0 : n * fact(n - 1); 
    }
    

    given every answer for n > 127 is 0. This avoid changing the source code.

提交回复
热议问题