Dec 22, 2008

How to increase the java stack size

Some times you might end up with a stack overflow Error. This is caused by the creation of larger data structures under the threads of execution. Sometimes the program logic may require a larger data structure for the functionality of it. But there can be growing data structures due to an error in the logic. In both these cases, if you go with the default stack size, then the probability of hitting an stack overflow error is high.

If your program really needs an extended stack, (not becuase of an error in the logic) then following option will increase the stack size.
java -Xss1024k MyProgram

The above command will increase the stack size of java upto 1024 KB.

The default java stack size is 400k, with a minimum value of 1000 bytes.It is possible to specify the amount using the MB as well. Use 'm' instead of 'k'  as given below.
java -Xss1m MyProgram

1 comments: