简体   繁体   English

StackOverflowError到我在Java中的递归调用

[英]StackOverflowError to my recursive calls in Java

i'm getting StackOverflowError to my recursive call: 我正在将StackOverflowError传递给我的递归调用:

    Exception in thread "main" java.lang.StackOverflowError
        at Test.trailMngr(Test.java:112)
        at Test.trailMngr(Test.java:115)
        at Test.trailMngr(Test.java:115)
        at Test.trailMngr(Test.java:115)
        at Test.trailMngr(Test.java:115)
        ...
    Java Result: 1

Is there a way to fix this without changing the code? 有没有办法解决这个问题而不改变代码?

The only way i can think of is making it a non-recursive method. 我能想到的唯一方法是使它成为一种非递归方法。

Everything else in the code is working fine in smaller input sizes-- i'll avoid the change if possible (although i'm not hopeful). 代码中的其他所有内容在较小的输入大小中都能正常工作 - 如果可能的话,我将避免更改(尽管我没有希望)。

Not well-familiar with how Java behaves on these things. 不太熟悉Java在这些方面的表现。

TIA. TIA。

Assuming you're not dealing with infinite recursion, you can increase the stack size using the command-line Xss parameter: 假设您没有处理无限递归,可以使用命令行Xss参数增加堆栈大小:

java -Xss8m Test

This is the amount of memory allocated for every thread's internal use. 这是为每个线程的内部使用分配的内存量。 Sizes can be specified in bytes ( -Xss8 ), kilobytes ( -Xss8k ), megabytes ( -Xss8m ) or gigabytes ( -Xss8g ). 大小可以以字节( -Xss8 ),千字节( -Xss8k ),兆字节( -Xss8m )或千兆字节( -Xss8g )指定。 Note that setting this to a high value will obviously increase your memory usage. 请注意,将此值设置为较高值显然会增加内存使用量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM