Java 堆栈溢出错误 - 如何在 Eclipse 中增加堆栈大小? [英] Java stack overflow error - how to increase the stack size in Eclipse?

查看:68
本文介绍了Java 堆栈溢出错误 - 如何在 Eclipse 中增加堆栈大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Eclipse 中运行我用 Java 编写的程序.对于非常大的输入,该程序具有非常深的递归级别.对于较小的输入,程序运行良好,但是当给出较大的输入时,我收到以下错误:

I am running a program that I've written in Java in Eclipse. The program has a very deep level of recursion for very large inputs. For smaller inputs the program runs fine however when large inputs are given, I get the following error:

Exception in thread "main" java.lang.StackOverflowError

这是否可以通过增加 Java 堆栈大小来解决?如果是,我该如何在 Eclipse 中执行此操作?

Can this be solved by increasing the Java stack size and if so, how do I do this in Eclipse?

更新:

@Jon Skeet

代码递归地遍历解析树以构建数据结构.因此,例如,代码将使用解析树中的一个节点来做一些工作,并在该节点的两个子节点上调用自身,将它们的结果组合起来给出树的整体结果.

The code is traversing a parse tree recursively in order to build up a datastructure. So, for example the code will do some work using a node in the parse tree and call itself on the node's two children, combining their results to give the overall result for the tree.

递归的总深度取决于解析树的大小,但是当递归调用的次数达到 1000 秒时,代码似乎会失败(没有更大的堆栈).

The total depth of the recursion depends on the size of the parse tree but the code seems to fail (without a larger stack) when the number of recursive calls gets into the 1000s.

此外,我很确定代码不会因为错误而失败,因为它适用于小输入.

Also I'm pretty sure the code isn't failing because of a bug as it works for small inputs.

推荐答案

为您的应用程序打开运行配置(运行/运行配置...,然后在Java 应用程序"中查找应用程序条目').

Open the Run Configuration for your application (Run/Run Configurations..., then look for the applications entry in 'Java application').

arguments 选项卡有一个文本框 Vm arguments,输入 -Xss1m(或最大堆栈大小的更大参数).默认值为 512 kByte(SUN JDK 1.5 - 不知道它是否因供应商和版本而异).

The arguments tab has a text box Vm arguments, enter -Xss1m (or a bigger parameter for the maximum stack size). The default value is 512 kByte (SUN JDK 1.5 - don't know if it varies between vendors and versions).

这篇关于Java 堆栈溢出错误 - 如何在 Eclipse 中增加堆栈大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆