7 garbage collectors

Serial Collector: Serial, Serial Old
Parallel Collector: ParNew, Parallel Scavenge, Parallel Old
Concurrent Collector: CMS, G1

The relationship between the garbage collector and the garbage generation

New generation collector: Serial, ParNew, Parallel Scavenge
Old generation collector: Serial Old, Parallel Old, CMS
whole heap collector: G1

Insert picture description here

Usage scenario:
Pay attention to throughput (Throughput) and low latency (Low latency) at the same time, the default pause target is 200 ms
super large heap memory, and the heap will be divided into multiple regions of equal size. The
overall labeling + sorting algorithm is two Copy algorithm between regions

Related JVM parameters
-XX:+UseG1GC
-XX:G1HeapRegionSize=size
-XX:MaxGCPauseMillis=time

How to view the default garbage collector

-XX:+PrintCommandLineFlags: View the command line related parameters (including the garbage collector used).
Use the command line command: jion -flag related garbage collection period parameter process id.
Insert picture description here
In the IDEA console, you can see that the gc used is: ParallelGC, then the corresponding The gc of the old age is ParallelGC Old GC.
Insert picture description here
When we use jinfo to view jvm information, the garbage collector used by jdk1.8 is UseParallelGC and UseParallelOldGC
commands:
jinfo [option] pid
option

  • The specific options and functions of option are as follows:

  • -flags view jvm parameters

  • -sysprops View java system parameters

-flag [+|-] Modify the JVM parameters of the running Java application, where + is to open the corresponding parameter,-is to close the corresponding parameter

D:\BaiduNetdiskDownload\谷粒商城\jvm\代码\JVMDemo>jps
7440 Jps
3988
10824 Launcher
9180 GCUseTest

D:\BaiduNetdiskDownload\谷粒商城\jvm\代码\JVMDemo>jinfo -flag UseParallelGC 9180
-XX:+UseParallelGC

D:\BaiduNetdiskDownload\谷粒商城\jvm\代码\JVMDemo>jinfo -flag UseParallelOldGC 9180
-XX:+UseParallelOldGC

Garbage collector choice:
If you want to minimize the use of memory and parallel overhead, please choose serial GC.
If you want to maximize the throughput (throughput) of your application, please choose Parallel GC
if you want to minimize GC interruptions and pauses. Time (low latency), please choose CMS GC

Guess you like

Origin blog.csdn.net/u014496893/article/details/114628171