Java 中的深度递归导致堆栈溢出? [英] Stack overflows from deep recursion in Java?

查看:36
本文介绍了Java 中的深度递归导致堆栈溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对函数式语言有了一些经验之后,我开始在 Java 中更多地使用递归 - 但该语言似乎具有大约 1000 个相对较浅的调用堆栈.

After some experience with functional languages, I'm starting to use recursion more in Java - But the language seems to have a relatively shallow call stack of about 1000.

有没有办法让调用栈变大?就像我可以创建数百万次调用深度的函数,就像在 Erlang 中一样?

Is there a way to make the call stack bigger? Like can I make functions that are millions of calls deep, like in Erlang?

我在解决欧拉项目问题时越来越注意到这一点.

I'm noticing this more and more when I do Project Euler problems.

谢谢.

推荐答案

我猜你可以使用这些参数

I guess you could use these parameters

-ss Stacksize 增加原生堆栈大小或

-ss Stacksize to increase the native stack size or

-oss Stacksize 增加Java堆栈大小,

-oss Stacksize to increase the Java stack size,

默认的原生栈大小是 128k,最小值为 1000 字节.默认的java堆栈大小是400k,最小值为 1000 字节.

The default native stack size is 128k, with a minimum value of 1000 bytes. The default java stack size is 400k, with a minimum value of 1000 bytes.

http://edocs.bea.com/wls/docs61/常见问题解答/java.html#251197

在阅读第一条评论(Chuck 的)以及重新阅读问题和阅读其他答案后,我想澄清一下,我将问题解释为增加堆栈大小".我并不打算说你可以拥有无​​限的堆栈,例如在函数式编程中(我只是触及了它的表面的一种编程范式).

After reading the first comment (Chuck´s), as well as re reading the question and reading another answers, i´d like to clarify that i interpreted the question as just "increase stack size". I didn´t intend to say that you can have infinite stacks, such as in functional programming (a programming paradigm which i´ve only scratched its surface).

这篇关于Java 中的深度递归导致堆栈溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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