How to avoid StackOverflowError for a recursive function

后端 未结 6 1530
无人共我
无人共我 2021-01-01 18:19

I\'m writing a function that will call itself up to about 5000 times. Ofcourse, I get a StackOverflowError. Is there any way that I can rewrite this code in a f

6条回答
  •  一生所求
    2021-01-01 19:13

    default stack size in java is 512kb. if you exceed that program will terminate throwing StackOverflowException

    you can increase the stack size by passing a JVM argument : -Xss1024k

    now stack size is 1024kb. you may give higher value based on your environment

    I don't think we can programmatically change this

提交回复
热议问题