StackOverflowError: default thread stack size (-Xss) behavior in HotSpot JVM with many threads
0 reputation · 02 Apr 2026, 03:42 UTC
The goal is to understand how the HotSpot JVM determines the default thread stack size when the application creates a large number of threads, especially for workloads that use deep recursion.
The JVM does not publish a fixed formula for the -Xss value; the chosen size depends on the JDK release, the underlying operating system, and possibly the detected memory layout. This variability can lead to unexpected StackOverflowError in recursive algorithms, forcing developers to tune the stack size manually.
What specific factors does the HotSpot JVM consider when computing the default -Xss value for a given platform?
How does the default stack size differ between JDK 11, 17, and 21 on Linux x86_64 systems?
Is there a reliable method to predict the default stack size without launching the JVM and inspecting the printed flags?