-Xss和-XX有什么区别:ThreadStackSize? [英] What is the difference between -Xss and -XX:ThreadStackSize?
问题描述
我只想控制Java(groovy)应用程序中所有线程的堆栈大小。对于Hotspot Oracle VM,我知道有两个参数可以做到这一点( -Xss
和 XX:ThreadStackSize
)。
I just want to control the stack size for all of my threads in a Java (groovy) application. For the Hotspot Oracle VM, I know that there are two parameters doing that (-Xss
and XX:ThreadStackSize
).
哪个是首选?它们之间有什么区别吗?关于Open JDK 7 有人在邮件列表中询问,声明 -Xss
对于Hotpot VM来说与 -XX:ThreadStackSize
相同。
Which is the preferred one? Is there any difference between them? Regarding Open JDK 7 someone asked on the mailing list, stating that -Xss
is the same for the Hotpot VM as -XX:ThreadStackSize
.
关键是,我正在测量可以在我的系统上启动多少个线程。
我的groovy脚本就是这样的:
The point is, that I am measuring how many threads can be started on my system. My groovy script which does this looks like:
int count = 0
def printCountThreads = {
println("XXX There were started $count threads.")
}
try {
while(true){
new Thread({Thread.sleep(Integer.MAX_VALUE)}).start()
count++
if(count % 1000 == 0){
printCountThreads()
}
}
} catch (Throwable e){
printCountThreads()
throw e
}
有趣的是,我只使用 - XX:ThreadStackSize
获得减少的线程数。我正在使用环境变量JAVA_OPTS中的不同内容启动groovy应用程序。
Interestingly enough I just get a reduced number of of threads using -XX:ThreadStackSize
. I am starting the groovy application with and with different content in the environment variable JAVA_OPTS.
groovy countmax-threads.groovy
当我将JAVA_OPTS设置为 -XX:ThreadStackSize = 2m
时,我会获得大约1000个启动的线程,直到消耗内存为止。但是,当我使用 JAVA_OPTS =' - Xss2m'
时,我会得到大约32000个线程,直到出现预期的错误。所以似乎 -Xss
根本不起作用。
When I set JAVA_OPTS to -XX:ThreadStackSize=2m
, I get about 1000 started threads until the memory is consumed. But, when I use JAVA_OPTS='-Xss2m'
, I get about 32000 threads until the expected error arises. So it seems that -Xss
does not work at all.
我正在使用
java version1.8.0_05
Java(TM)SE运行时环境(版本1.8.0_05-b13)
Java HotSpot(TM)64位服务器VM(版本25.5-b02,混合模式)
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
在具有四个硬件线程和大约8 GB RAM的Ubuntu 14.04 64位计算机上。
on a Ubuntu 14.04 64 bit machine with four hardware threads and about 8 GB of RAM.
更新:
我在Windows 7 64位机器和另一台JDK上重新验证了这一点:
I reverified this on my Windows 7 64 bit machine and another JDK:
java版1.8.0_20
Java(TM)SE运行时环境(版本1.8.0_20-b26)
Java HotSpot(TM)64位服务器VM(版本25.20-b23,混合模式)
java version "1.8.0_20" Java(TM) SE Runtime Environment (build 1.8.0_20-b26) Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
并且 -Xss
和 -XX:ThreadStackSize
按预期工作(正如一些答案所指出的那样)。所以我认为这是一个特定于Linux的问题,甚至是JDK版本1.8.05中的一个错误。
and there -Xss
and -XX:ThreadStackSize
work as expected (as some answers pointed out). So I suppose it is a Linux specific problem or even a bug in the JDK version 1.8.05.
推荐答案
-Xss
是Java HotSpot VM识别的标准选项。
-Xss
is standard options recognized by the Java HotSpot VM.
-XX:ThreadStackSize
其他 -XX
期权不稳定,如有更改,恕不另行通知。
-XX:ThreadStackSize
as other -XX
options are not stable and are subject to change without notice.
这篇关于-Xss和-XX有什么区别:ThreadStackSize?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!