Reputation: 55
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?
Upvotes: 5
Views: 2888
Reputation: 4348
I want to add a couple of very useful resources:
The default is 1M per thread, but fortunately the things are not so bad. OS allocates memory pages lazily, i.e. on the first use, so the actual memory usage will be much lower (typically 80-200 KB per thread stack).
in JDK 11/12 [minimum thread stack size] is: min_stack_size = 40 KB + (1 + 2 + 1 + 20) * 4 KB = 136 KB
If I try to set a lower value, I’ll expectedly get an error:
/usr/java/jdk-12.0.2/bin/java -Xss100k
The Java thread stack size specified is too small. Specify at least 136k
Upvotes: 2
Reputation: 1027
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
Upvotes: 2