Reputation: 75
I am running into Java StackOverFlowError upon running a recursive program. The program is correct and the recursion needs to be implemented. I tried to find the current stack size using the command
java -XX:+PrintFlagsFinal -version | grep ThreadStackSize
and this is what i got:
intx CompilerThreadStackSize = 0 {pd product}
intx ThreadStackSize = 1024 {pd product}
intx VMThreadStackSize = 1024 {pd product}
java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
What does this mean? And how can I increase the stacksize and what value should i set? Is it normal to get this error for the above settings?Please help.
Upvotes: 0
Views: 1184
Reputation: 8587
It means the stack size is 1MB (1024KB). And you can increase the thread stack size by passing -Xss<size>
, for example to set the stack size to 32 MB for each thread:
java -Xss32m
Usually a stack size of 1MB is enough. For most of the projects I worked on, I rarely need to change the stack size. So quite possibly your code is not correct as you think.
Upvotes: 1
Reputation: 32376
If you are writing a recursive code and it doesn't have code to terminate the recursion then you will eventually get the stackoverflow error , no matter how much high is your stack size.
There is nothing which you can do apart from fixing your code, which causes this error.
Upvotes: 0