I am considering increasing the stack size to work around the StackOverflowError thrown by the regex library which does not appear to be on the plans for a fix.
Within Java, the Java threads are represented by thread objects. Each thread also has a stack, used for storing runtime data. The thread stack has a specific size.
If we don't specify a size for the stacks, the JVM will create one with a default size. Usually, this default size depends on the operating system and computer architecture. For instance, these are some of the default sizes as of Java 14: Linux/x86 (64-bit): 1 MB.
By default in 64-bit JVMs, this is 1MB. That doesn't mean each thread will actually consume 1MB of physical resources. All it means is the JVM will malloc 1MB for each thread for its stack. All modern operating systems lazily allocate physical ram.
There is one stack per process, which gets subdivided into non-overlapping parts, one substack per thread.
Is the entire Xss (stack space) used for each Java thread?
According to this page, yes:
- increase the stack size for all threads in your application, by including -Xssnnm in the Java command line (where nn is the number of megabytes of stack space per thread);
You can however choose a larger stack size for a specific thread using the Thread(ThreadGroup group, Runnable target, String name, long stackSize)
constructor.
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, belongs to the thread group referred to by group, and has the specified stack size.
Note however that (according to documentation) the effect of the stackSize
parameter, if any, is highly platform dependent and that the value of the stackSize
parameter may have no effect whatsoever on some platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With