1

I am writing a function in Java which has to recursively call itself a lot of times (in the range of ~10000). After reaching some level of recursion (~3250 atm), the Java thread just holds and has to be restarted. This is not influenced by the amount of RAM the jvm is started with (currently it's 2GB).

How can I influence the maximum level of nesting my jvm can handle?

Thomas
  • 10,289
  • 13
  • 39
  • 55

1 Answers1

5

In this order, try:

  1. Changing your algorithm (you should be able to use stack and loop instead).

  2. Using tail recursion (i.e.: change your language, supports tail recursion)

  3. Passing -Xss1m parameter to the JVM to increase stack size. 1m means 1 MiB.

See also

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Thank you very much. Increasing the stack size did the trick, because the other two options were not applicable atm. – Thomas Aug 28 '12 at 18:52