If I recursivley call a method in Java, in advance can I know how many calls would succeed before I get StackOverflowException? i.e Some kind of stack size that is hopefully configurable in WAS?
-
You could, in theory, calculate the size of one stack frame, then divide the configured stack size by that to get the number of calls. But that calculation is not easy. – Raedwald Jun 24 '13 at 22:37
-
possible duplicate of [How to predict the maximum call depth of a recursive method?](http://stackoverflow.com/questions/13995885/how-to-predict-the-maximum-call-depth-of-a-recursive-method) – default locale Jun 25 '13 at 03:28
2 Answers
Depends on the size of your stack. For Oracle's java, run java -X
for a list of parameters that can be set, including -Xss<size>
to set stack size. See this for some details.
If by WAS you are referring to the Websphere Application Server
, you should have a config panel somewhere in the admin console for setting such java parameters. It use to be, and I assume it still is, that the IBM java command line parameters were a super-set of the Oracle parameters.

- 1
- 1

- 8,262
- 3
- 36
- 48
It depends on the amount of data being pushed onto the stack (local variables), as well as how much memory is allocated to the stack. Each recursive call will consume the amount of data equal to the sum of all local and signature variables. That is why recursive calls should be avoided unless the maximum depth of recursion is fairly shallow.
You can increase the amount of memory allocated for stack using the -Xss<size>
argument to the JVM. How to increase the Java stack size?

- 1
- 1

- 19,192
- 5
- 36
- 77