java jvm 的默认垃圾收集器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5175234/
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
Default Garbage collector for a jvm
提问by user640121
Possible Duplicate:
find which type of garbage collector is running
可能的重复:
查找正在运行的垃圾收集器类型
Is there a way to tell what garbage collector is being used in a jvm by default?
有没有办法告诉默认情况下在 jvm 中使用的是什么垃圾收集器?
回答by Will Hartung
This will print out a list of all of the Garbage Collectors currently loaded in your JVM.
这将打印出当前加载到 JVM 中的所有垃圾收集器的列表。
import java.lang.management.*;
import java.util.List;
public class x {
public static void main(String args[]) {
List<GarbageCollectorMXBean> l = ManagementFactory.getGarbageCollectorMXBeans();
for(GarbageCollectorMXBean b : l) {
System.out.println(b.getName());
}
}
}
回答by Michael Berry
回答by Stephen C
I think that the answer is that you cannot directly tell what the default garbage collector is. You can tell what garbage collectors are currently used in the current JVM, but that depends on other factors ... such as the JVM options ... so you cannot reliably infer the default GC from that.
我认为答案是您无法直接说出默认垃圾收集器是什么。您可以判断当前 JVM 中当前使用了哪些垃圾收集器,但这取决于其他因素……例如 JVM 选项……因此您无法从中可靠地推断出默认 GC。
Furthermore (not withstanding what @Lucas says), inferring (reliably) what the default is by other means would be hard:
此外(不管@Lucas 怎么说),通过其他方式推断(可靠地)默认值是很困难的:
As @Lucas points out, the default depends on whether the machine falls into the "server-class" category, and in some cases that depends on physical properties of the machine that are impossible to access portably.
The documentation of the process is patchy, and not necessarily entirely reliable.
The behaviour ("server-class" classification, default GC per class, etc) is liable to depend on the Java version. Indeed, it may even change with JVM patch releases.
正如@Lucas 指出的那样,默认值取决于机器是否属于“服务器类”类别,并且在某些情况下取决于机器的物理属性,这些物理属性无法移植。
该过程的文档不完整,不一定完全可靠。
行为(“服务器类”分类、每个类的默认 GC 等)可能取决于 Java 版本。事实上,它甚至可能随着 JVM 补丁的发布而改变。
IMO, a better approach would be to explicitly set the JVM options when launching the child process, and don't rely on the defaults. Alternatively, just go with whatever the default is.
IMO,更好的方法是在启动子进程时显式设置 JVM 选项,而不依赖于默认值。或者,只需使用默认值即可。