admin管理员组文章数量:1357273
How does the -Xss play a key role in java program?
The size of the stack directly affects the program running.
- As I know -Xss decides the thread stack size of jvm, includ local variables, operand stacks, dynamic link information, return addresses and so on.
- Usually in my local development environment, I usually set -Xss 4M.
I ran a simple recursive program, and it StackOverflowError.
public class StackOverflowErrorExample {
private static int count = 0;
public static void recursiveFunction() {
count++;
recursiveFunction(); // recursive
}
public static void main(String[] args) {
try {
recursiveFunction();
} catch (StackOverflowError e) {
System.out.println("overflow: " + count);
e.printStackTrace();
}
}
}
How does the -Xss play a key role in java program?
The size of the stack directly affects the program running.
- As I know -Xss decides the thread stack size of jvm, includ local variables, operand stacks, dynamic link information, return addresses and so on.
- Usually in my local development environment, I usually set -Xss 4M.
I ran a simple recursive program, and it StackOverflowError.
public class StackOverflowErrorExample {
private static int count = 0;
public static void recursiveFunction() {
count++;
recursiveFunction(); // recursive
}
public static void main(String[] args) {
try {
recursiveFunction();
} catch (StackOverflowError e) {
System.out.println("overflow: " + count);
e.printStackTrace();
}
}
}
Share
Improve this question
edited Mar 28 at 6:12
MoXi
asked Mar 28 at 3:11
MoXiMoXi
12 bronze badges
2
- -Xss4M overflow count : 216555 in my computer. – MoXi Commented Mar 28 at 3:25
- 2 In general, the most appropriate setting is no setting. Use the default. – Stephen C Commented Mar 28 at 3:58
1 Answer
Reset to default 1What is the appropriate value of the jvm -Xss parameter?
It depends. But typically, you wouldn't set it at all.
How does the -Xss play a key role in java program?
The role is that is sets the default stack size for threads. Whether it is a "key" role depends on the application. However:
- if the stack size is too small, some (otherwise correct1) programs will fail
- if the stack size is too large you will waste memory, especially if you have many threads.
Note that there will be stack for each application thread, and unless the thread is created with an explicit stack size (i.e. using this constructor) the -Xss
value (or its default) will be used for each thread's stack.
The size of the stack directly affects the program running.
In some cases. In most cases the default stack size (i.e. what you get if you don't specify -Xss
) is just fine. It depends on the application.
Finally, your test code is going overflow the stack no matter what -Xss
is set to. It is simply a pathological program ... and it is not useful for deciding what -Xss
a typical real application requires.
1 - Correctness is nuanced. For example, given that we know that Java implementations don't implement tail-call elimination, it is debatable whether it is correct to implement traversal of a linked list using recursion. If you do, and the list is large, and the stack isn't large enough, then the application will SOE.
本文标签: javaWhat is the appropriate value of the jvm Xss parameterStack Overflow
版权声明:本文标题:java - What is the appropriate value of the jvm -Xss parameter? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744058885a2583757.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论