Java Quickie: Change/ Increase Stack Size

Tired of StackOverflowErrors? Increase stack size or change algorithm. Learn how with this Java Quickie 

A common reason behind the StackOverflowError is due to a faulty recursion algorithm. For example calling the function inside the function untill infinity. You don’t need to increase stack size for this error because it wont help you. Just improve that algorithm. Maybe add a condition: This thread offers an example of how to stop a recursion.

For algorithms that require a bigger stack you can change the stack size for your application with this command:

$ java -Xss:256k techbrewApplication

With this example above, you’ll increase the stack size to 256 KiloBytes for your application. Normal values range from 64 to 512KB.

An in-depth explanation of stacks can be found here. More Java here.