Search code examples
javamultithreadingstackjvm-arguments

Xss set thread stack size for 1 thread, what is the limitation for all thread's stack size


I know how to set stack size for java thread using -Xss, and we use it in our product.

But when there are lots of thread used in our application , and -Xss is set (we set to 512k for our usage). we will encounter error reporting unable to create new native thread. it should be related to stack size , as when we set -Xss256k, the error gone.

My question is for 1 thread, Xss set stack size, but how about for all threads stack size?
what is the limitation of whole Thread's total stack memory size? i didn't find such JVM setting, while we do seems encounter such problem now.


Solution

  • -Xss sets the default amount of virtual memory reserved for each new thread's stack. (That is, for each new thread that is not given an explicit stack size through its constructor.)

    There is no option to limit the combined stack sizes for all threads.

    If setting -Xss down from 512K to 256K enables your program to create more threads, then your program must be creating an awful lot of threads.

    What are all of those threads doing?

    Are you sure you can't solve the problem using a limited number of threads in a thread pool?