Using XSS memory parameter to control stackoverflowerror

Each thread in a Java application has its own stack. The stack is used to hold return addresses, function/method call arguments, etc. So if a thread tends to process large structures via recursive algorithms, it may need a large stack for all those return addresses and such. With the Sun JVM, you can set that size via that parameter.

The thread stack is used to push stacks frames in nested method calls. If the nesting is so deep that the thread runs out of space, the thread dies with a StackOverflowError.

The default thread stack size varies with JVM, OS and environment variables. A typical value is 512k.

This is the sample code which will deliberately makes recursive calls so that we can simulate stackoverflow error. For default 1M XSS memory, it runs approx 8k times before running out of space. For 512k, it runs 4k time and for 2M XSS memory, it runs 19k times

Uday Ogra

Connect with me at http://facebook.com/tendulkarogra and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *