Search code examples
javaspring-bootperformancejvmjvm-arguments

How to fine tune JVM configurations to reduce the max thread stack size?


I want to change the default thread stack size in Java for my Spring-Boot Web application. How can I change this? or which parameter I need to use to change this value?

Also, the second question is, can I programmatically change this at runtime?


Solution

  • Yes, you can do that. Basically, you can configure the max Stack size of your thread in your application.

    For this, you can use the option named ss to adjust the maximum stack size. A VM option is usually passed using -X{option}. So you can use java -Xss1M to set the maximum of stack size to 1M.

    One more example is java -Xss1048576, this sets the max thread size to approximately 1 MB

    Checkout the two below blogs also for more info and other flags.

    -> https://www.baeldung.com/jvm-configure-stack-sizes

    -> https://docs.gigaspaces.com/latest/production/production-jvm-tuning.html