简体   繁体   English

Java 8 的默认垃圾收集器

[英]Default garbage collector for Java 8

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 时,他们发现它是新一代的并行收集器和老一代的旧串行收集器。

Default garbage collectors:默认垃圾收集器:

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

Selecting the default garbage collector (among other things) is what's called the ergonomics process of the JVM.选择默认的垃圾收集器(除其他外)就是所谓的 JVM 的人体工程学过程。 This process depends on the class of your machine.此过程取决于您的机器类别。

  • 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).对于服务器级机器,定义为具有 2 个或更多物理处理器和 2 GB 或更多物理内存(与平台无关)的机器,默认垃圾收集器是并行收集器(也称为吞吐量收集器)。
  • 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.对于客户端级机器,定义为 Windows 上的 32 位平台或单处理器机器,默认垃圾收集器是串行收集器。

Since practically all machines have 2 or more CPU, a machine is practically always considered server-class by the JVM.由于几乎所有机器都有 2 个或更多 CPU,因此 JVM 实际上总是将机器视为服务器级。 That's why you will find a lot of references considering the parallel collector to be the default garbage collector.这就是为什么您会发现很多参考资料都将并行收集器视为默认垃圾收集器。

Java has four types of garbage collectors(Up to version 10),but after stable release of java 11 , it would be 5 types. Java有四种类型的垃圾收集器(直到版本10),但是在Java 11稳定发布后,它将是5种类型。 These are:-这些是:-

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

Default implementations of GC in java - java中GC的默认实现 -

JVM GC 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.如果您想根据需要设置 GC,可以通过以下命令进行。 Here I am going to set G1 GC as default GC.这里我将 G1 GC 设置为默认 GC。

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

在此处输入图片说明

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

从 Java 9 到 Java 15,G1GC 是默认设置,即使在 Java 15 上也是默认的,它增加了两个新一代垃圾收集器,甲骨文开发的 ZGC 和红帽实现,即雪兰多,两者都在 2020 年 9 月的 Java 15 中投入生产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM