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?
In this order, try:
Changing your algorithm (you should be able to use stack and loop instead).
Using tail recursion (i.e.: change your language, scala supports tail recursion)
Passing
-Xss1mparameter to the JVM to increase stack size.1mmeans 1 MiB.See also