oracle -Xss 和 -XX:ThreadStackSize 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28767905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between -Xss and -XX:ThreadStackSize?
提问by user2078148
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
).
我只想控制 Java(常规)应用程序中所有线程的堆栈大小。对于 Hotspot Oracle VM,我知道有两个参数可以做到这一点(-Xss
和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
.
哪个是首选?它们之间有什么区别吗?关于 Open JDK 7,有人在邮件列表中询问,指出-Xss
Hotpot VM 与-XX:ThreadStackSize
.
The point is, that I am measuring how many threads can be started on my system. My groovy script which does this looks like:
关键是,我正在测量可以在我的系统上启动多少线程。我执行此操作的 groovy 脚本如下所示:
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
}
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.
有趣的是,我只是减少了使用 - 的线程数量XX:ThreadStackSize
。我正在使用环境变量 JAVA_OPTS 中的不同内容启动 groovy 应用程序。
groovy countmax-threads.groovy
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_OPTS 设置为 时-XX:ThreadStackSize=2m
,我会得到大约 1000 个已启动的线程,直到内存耗尽。但是,当我使用 时JAVA_OPTS='-Xss2m'
,我会得到大约 32000 个线程,直到出现预期的错误。所以这似乎-Xss
根本不起作用。
I am using
我在用
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)
java 版本“1.8.0_05”
Java(TM) SE 运行时环境(构建 1.8.0_05-b13)
Java HotSpot(TM) 64 位服务器 VM(构建 25.5-b02,混合模式)
on a Ubuntu 14.04 64 bit machine with four hardware threads and about 8 GB of RAM.
在具有四个硬件线程和大约 8 GB RAM 的 Ubuntu 14.04 64 位机器上。
UPDATE:
更新:
I reverified this on my Windows 7 64 bit machine and another JDK:
我在我的 Windows 7 64 位机器和另一个 JDK 上重新验证了这一点:
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)
java 版本“1.8.0_20”Java(TM) SE 运行时环境(构建 1.8.0_20-b26)Java HotSpot(TM) 64 位服务器 VM(构建 25.20-b23,混合模式)
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
并按-XX:ThreadStackSize
预期工作(正如一些答案所指出的那样)。所以我想这是一个 Linux 特定的问题,甚至是 JDK 1.8.05 版中的一个错误。
采纳答案by alain.janinm
-Xss
is standard options recognized by the Java HotSpot VM.
-Xss
是 Java HotSpot VM 识别的标准选项。
-XX:ThreadStackSize
as other -XX
options are not stable and are subject to change without notice.
-XX:ThreadStackSize
因为其他-XX
选项不稳定,如有更改,恕不另行通知。
回答by apangin
-Xss
is an alias for -XX:ThreadStackSize
both for OpenJDK and Oracle JDK.
-Xss
是-XX:ThreadStackSize
OpenJDK 和 Oracle JDK的别名。
Though they parse arguments differently:-Xss
may accept a number with K, M or G suffix;-XX:ThreadStackSize=
expects an integer (without suffix) - the stack size in kilobytes.
尽管它们解析参数的方式不同:-Xss
可以接受带有 K、M 或 G 后缀的数字;-XX:ThreadStackSize=
需要一个整数(无后缀) - 以千字节为单位的堆栈大小。
回答by Alan Thompson
UPDATED 2019 for Java SE 8
Java SE 8 的 2019 年更新
Current Oracle Java SE 8 docs suggest that -Xss
and -XX:ThreadStackSize=size
are equivalent. See
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
当前的 Oracle Java SE 8 文档表明-Xss
和-XX:ThreadStackSize=size
是等效的。请参阅
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
For -Xss
:
对于-Xss
:
-Xsssize
Sets the thread stack size (in bytes). Append the
letter k or K to indicate KB, m or M to indicate MB, g or G to
indicate GB. The default value depends on the platform:
Linux/ARM (32-bit): 320 KB
Linux/i386 (32-bit): 320 KB
Linux/x64 (64-bit): 1024 KB
OS X (64-bit): 1024 KB
Oracle Solaris/i386 (32-bit): 320 KB
Oracle Solaris/x64 (64-bit): 1024 KB
The following examples set the thread stack size to 1024 KB in different units:
-Xss1m
-Xss1024k
-Xss1048576
This option is equivalent to -XX:ThreadStackSize.
For -XX:ThreadStackSize=size
为了 -XX:ThreadStackSize=size
-XX:ThreadStackSize=size
Sets the thread stack size (in bytes). Append the
letter k or K to indicate kilobytes, m or M to indicate
megabytes, g or G to indicate gigabytes. The default
value depends on the platform:
Linux/ARM (32-bit): 320 KB
Linux/i386 (32-bit): 320 KB
Linux/x64 (64-bit): 1024 KB
OS X (64-bit): 1024 KB
Oracle Solaris/i386 (32-bit): 320 KB
Oracle Solaris/x64 (64-bit): 1024 KB
The following examples show how to set the thread stack size to 1024 KB in different units:
-XX:ThreadStackSize=1m
-XX:ThreadStackSize=1024k
-XX:ThreadStackSize=1048576
This option is equivalent to -Xss.
回答by lichengwu
-Xss
works only on main
Java thead, but -XX:ThreadStackSize
works on all Java thread.
-Xss
仅适用于 Java 线程main
,但-XX:ThreadStackSize
适用于所有 Java 线程。
If -Xss (or -ss) were passed on the command line, it gets picked up directly by the launcher and is used later to create the "main" Java thread, without asking the VM for the preferred thread stack size. That where inconsistency comes from: if -Xss is given after -XX:ThreadStackSize, then things are still good; otherwise, the "main" Java thread would have a stack size specified by -Xss where as other Java threads' stack size would still follow that of ThreadStackSize.
如果 -Xss(或 -ss)在命令行上被传递,它会被启动器直接选取并稍后用于创建“主”Java 线程,而不需要向 VM 询问首选线程堆栈大小。不一致的原因是:如果在 -XX:ThreadStackSize 之后给出 -Xss,那么事情仍然很好;否则,“主”Java 线程的堆栈大小将由 -Xss 指定,而其他 Java 线程的堆栈大小仍将遵循 ThreadStackSize 的堆栈大小。
Inconsistency between -Xss and -XX:ThreadStackSize in the java launcher