Java 8 的默认垃圾收集器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33206313/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:26:44  来源:igfitidea点击:

Default garbage collector for Java 8

javagarbage-collectionjava-8

提问by Code Junkie

What is the default garbage collector for Java 8?

Java 8 的默认垃圾收集器是什么?

When I check the JMX Beans, they reveal it to be the parallel collector for the new generation and the old serial collector for the old generation.

当我检查 JMX Beans 时,他们发现它是新一代的并行收集器和老一代的旧串行收集器。

回答by Tunaki

Selecting the default garbage collector (among other things) is what's called the ergonomicsprocess of the JVM. This process depends on the class of your machine.

选择默认的垃圾收集器(除其他外)就是所谓的 JVM的人体工程学过程。此过程取决于您的机器类别。

  • For server-class machine, defined as a machine with 2 or more physical processors and 2 or more GB of physical memory (regardless of the platform), the default garbage collector is the parallel collector(also known as throughput collector).
  • For client-class machine, defined as a 32-bit platform on Windows or a single-processor machine, the default garbage collector is the serial collector.
  • 对于服务器级机器,定义为具有 2 个或更多物理处理器和 2 GB 或更多物理内存(与平台无关)的机器,默认垃圾收集器是并行收集器(也称为吞吐量收集器)。
  • 对于客户端级机器,定义为 Windows 上的 32 位平台或单处理器机器,默认垃圾收集器是串行收集器。

Since practically all machines have 2 or more CPU, a machine is practically always considered server-class by the JVM. That's why you will find a lot of references considering the parallel collector to be the default garbage collector.

由于几乎所有机器都有 2 个或更多 CPU,因此 JVM 实际上总是将机器视为服务器级。这就是为什么您会发现很多参考资料都将并行收集器视为默认垃圾收集器。

回答by x4444

Default garbage collectors:

默认垃圾收集器:

  • Java 7 - Parallel GC
  • Java 8 - Parallel GC
  • Java 9 - G1 GC
  • Java 10 - G1 GC
  • Java 7 - 并行 GC
  • Java 8 - 并行 GC
  • Java 9 - G1 GC
  • Java 10 - G1 GC

回答by Brajesh

Java has four types of garbage collectors(Up to version 10),but after stable release of java 11 , it would be 5 types. These are:-

Java有四种类型的垃圾收集器(直到版本10),但是在Java 11稳定发布后,它将是5种类型。这些是:-

  1. Serial Garbage Collector- S GC
  2. Parallel Garbage Collector- P GC
  3. CMS Garbage Collector- CMS GC
  4. G1 Garbage Collector- G1 GC
  5. The Z Garbage Collector- ZGC
  1. 串行垃圾收集器- S GC
  2. 并行垃圾收集器- P GC
  3. CMS垃圾收集器- CMS GC
  4. G1垃圾收集器- G1 GC
  5. Z垃圾收集器- ZGC

Default implementations of GC in java -

java中GC的默认实现 -

JVM GC

 Java 7 - P GC       
 Java 8 - P GC
 Java 9 - G1 GC
 Java 10- G1 GC
 Java 11- Z GC(I am not sure but it would be default GC of java 11)

JVM 垃圾回收

 Java 7 - P GC       
 Java 8 - P GC
 Java 9 - G1 GC
 Java 10- G1 GC
 Java 11- Z GC(I am not sure but it would be default GC of java 11)

More details for ZGC,please visit

ZGC的更多详细信息,请访问

http://openjdk.java.net/projects/zgc/

http://openjdk.java.net/projects/zgc/

https://www.opsian.com/blog/javas-new-zgc-is-very-exciting/

https://www.opsian.com/blog/javas-new-zgc-is-very-exciting/

Note:If you want to verify, which GC is currently being used by JVM,you can go for following command to show default GC:-

注意:如果要验证 JVM 当前正在使用哪个 GC,可以执行以下命令以显示默认 GC:-

$ java -XX:+PrintCommandLineFlags -version 

If you want to set GC according to your need, you can do this by following command. Here I am going to set G1 GC as default GC.

如果您想根据需要设置 GC,可以通过以下命令进行。这里我将 G1 GC 设置为默认 GC。

$ java -XX:+UseG1GC -XX:+PrintCommandLineFlags -version 

enter image description here

在此处输入图片说明

For more details , please visit 

https://javapapers.com/java/types-of-java-garbage-collectors/

https://javapapers.com/java/types-of-java-garbage-collectors/

https://alvinalexander.com/java/java-jvm-how-show-which-garbage-collector-running

https://alvinalexander.com/java/java-jvm-how-show-which-garbage-collector-running