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

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

问题描述

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

 线程main java.lang.StackOverflowError 

这可以通过增加Java堆栈大小来解决吗?我在Eclipse中这样做?



更新:



@Jon Skeet

代码以递归方式遍历解析树,以构建数据结构。因此,例如,代码将使用解析树中的节点进行一些工作,并在节点的两个子节点上调用自己的结果,结合其结果给出树的总体结果。



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



另外我很确定代码没有失败,因为它适用于小的输入。

解决方案

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



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


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

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

Update:

@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.

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.

解决方案

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

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天全站免登陆