Dynamically expandable JVM stack

▼魔方 西西 提交于 2019-12-04 15:18:50

The maximum stack size is the amount of virtual address space that gets allocated to the stack. Memory is only committed to the stack as required.

Note that on 32-bit systems, virtual address space is a relatively scarce resource. You get less (sometimes much less) than 4GB per process. With this in mind, a 20MB stack would limit the number of threads to anywhere between 75 and 175.

Regarding dynamic expansion, even though the specification may support it the implementation might not.

So, How to tell the JVM to dynamically allocate its stack when needed?

You Dont. You leave all settings as default and if the computation in a thread requires a larger stack than is permitted, the Java virtual machine throws a StackOverflowError.

This is your cue to use -Xss to explicitly increase memory allocation to new threads.

This does not affect the JVM Heap. [see -Xmx -Xms for setting heap size]

Also I must say, 20Mb seems slightly excessive per thread.

All depends on the size of your heap and the number of concurrent threads you would like to support.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!