緊接前2篇文章,咱們今天來聊聊升級 Java11 以後的一寫 Jvm 參數變化。Java11 刪除掉了 cms 垃圾回收器,若是你升級到了 Java11 可是 Jvm 參數仍然使用 cms 垃圾回收器參數時控制檯會報錯,甚至會啓動失敗。java
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Unrecognized VM option 'ParallelCMSThreads=2'
Did you mean 'ParallelGCThreads=<value>'? Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
複製代碼
Option and Default Value | Description |
---|---|
-XX:+UseG1GC | Use the Garbage First (G1) Collector |
-XX:MaxGCPauseMillis=n | Sets a target for the maximum GC pause time. This is a soft goal, and the JVM will make its best effort to achieve it. |
-XX:InitiatingHeapOccupancyPercent=n | Percentage of the (entire) heap occupancy to start a concurrent GC cycle. It is used by GCs that trigger a concurrent GC cycle based on the occupancy of the entire heap, not just one of the generations (e.g., G1). A value of 0 denotes 'do constant GC cycles'. The default value is 45. |
-XX:NewRatio=n | Ratio of old/new generation sizes. The default value is 2. |
-XX:SurvivorRatio=n | Ratio of eden/survivor space size. The default value is 8. |
-XX:MaxTenuringThreshold=n | Maximum value for tenuring threshold. The default value is 15. |
-XX:ParallelGCThreads=n | Sets the number of threads used during parallel phases of the garbage collectors. The default value varies with the platform on which the JVM is running. |
-XX:ConcGCThreads=n | Number of threads concurrent garbage collectors will use. The default value varies with the platform on which the JVM is running. |
-XX:G1ReservePercent=n | Sets the amount of heap that is reserved as a false ceiling to reduce the possibility of promotion failure. The default value is 10. |
-XX:G1HeapRegionSize=n | With G1 the Java heap is subdivided into uniformly sized regions. This sets the size of the individual sub-divisions. The default value of this parameter is determined ergonomically based upon heap size. The minimum value is 1Mb and the maximum value is 32Mb. |
G1GC | -Xlog:gc |
Log messages with gc tag using info level to stdout, with default decorations. |
---|---|---|
G1GC | -Xlog:gc,safepoint |
Log messages with either gc or safepoint tags (exclusive), both using 'info' level, to stdout, with default decorations. |
G1GC | -Xlog:gc+ref=debug |
Log messages with both gc and ref tags, using debug level, to stdout, with default decorations. |
G1GC | -Xlog:gc=debug:file=gc.txt:none |
Log messages with gc tag using debug level to file gc.txt with no decorations. |
G1GC | -Xlog:gc=trace:file=gc.txt:uptimemillis, pids:filecount=5,filesize=1m |
Log messages with gc tag using trace level to a rotating logs of 5 files of size 1MB, using the base name gc.txt, with uptimemillis and pid decorations. |
G1GC | -Xlog:gc::uptime,tid |
Log messages with gc tag using info level to output stdout, using uptime and tid decorations. |
G1GC | -Xlog:gc*=info,safepoint*=off |
Log messages with at least gc using info level, but turn off logging of messages tagged with safepoint. |
-server
-Xmx4g
-Xms4g
-Xss256k
-XX:MaxDirectMemorySize=256m
-XX:+UseG1GC
-XX:+UseCompressedOops
-XX:+UseCompressedClassPointers
-XX:+SegmentedCodeCache
-verbose:gc
-XX:+PrintCommandLineFlags
-XX:+ExplicitGCInvokesConcurrent
-Djava.security.egd=file:/dev/./urandom
-Xlog:gc*,safepoint:/data/log/${SERVICE_NAME}/gc.log:time,uptime:filecount=100,filesize=50M
複製代碼
G1GC 沒必要明確設置新生代大小,其自動調優也十分可靠,對於停頓時間每每在長時間運行後能夠達到預期效果。 不建議進行過多的配置,對於 gc log 筆者認爲仍是頗有必要,各位同窗能夠按照本身的實際需求進行配置。git
本系列文章由微服務核心組件mica做者如夢技術整理撰寫, 若有參考或者轉載,請保留原做者和註明出處。 dom