JDK版本:8
JVM常用参数
-Xms 初始堆内存大小(包括年轻代和年老代)
-Xmx 最大堆内存大小(包括年轻代和年老代,建议和-Xms配置成一样)
-Xmn 年轻代堆内存大小
-XX:MetaspaceSize 初始元空间内存大小(个人认为不需要配置,因为用不了这么多)
-XX:MaxMetaspaceSize 最大元空间内存大小(个人认为不需要配置,因为用不了这么多)
-XX:+UseConcMarkSweepGC 设置年老代使用CMS垃圾回收器(JDK8默认使用Parallel Scavenge + Parallel Old进行垃圾回收,如果想使用CMS垃圾回收器,需要添加此配置)
-XX:+UseCMSInitiatingOccupancyOnly 开启<触发回收的阈值>属性
-XX:CMSInitiatingOccupancyFraction 设置触发回收的阈值(个人认为不需要配置,因为JVM占用的内存是程序启动时就分配好的,所以没必要留余地,用满了会触发GC)
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses 减少Full GC STW时长
-XX:+CMSClassUnloadingEnabled 开启CMS垃圾回收器对永久代类元数据的回收
-XX:+ParallelRefProcEnabled 开启并发处理Reference对象
-XX:+CMSScavengeBeforeRemark 在标记前触发一次young gc
-verbose:class 打印JVM加载类的信息(只有类的全限定名和所在jar包名)
-XX:+HeapDumpOnOutOfMemoryError oom时自动生成dump文件**(重要)**
-XX:ErrorFile=/data/logs/hs_err_pid%p.log error日志文件保存路径
-Xloggc:/dev/shm/gc/gc.log GC日志文件保存路径
-XX:HeapDumpPath=/data/logs/ dump文件保存路径
-XX:+PrintGCDetails 打印GC详细信息
-XX:+PrintGCDateStamps 打印GC
-XX:+PrintClassHistogramBeforeFullGC full gc前打印类直方图
-XX:+PrintClassHistogramAfterFullGC full gc后打印类直方图
-XX:+PrintCommandLineFlags 打印自动化参数
-XX:+PrintGCApplicationConcurrentTime 打印两个安全点之间应用程序运行的时间
-XX:+PrintGCApplicationStoppedTime 打印两个安全点之间应用程序停止的时间
-XX:+PrintTenuringDistribution 打印对象岁数
-XX:+PrintHeapAtGC 每次gc后打印堆信息
推荐方案
8G内存 并发较高的应用
-Xms4096M
-Xmx4096M
-Xmn2048M
-XX:MetaspaceSize=512M
-XX:MaxMetaspaceSize=512M
-XX:+UseConcMarkSweepGC
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=70
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses
-XX:+CMSClassUnloadingEnabled
-XX:+ParallelRefProcEnabled
-XX:+CMSScavengeBeforeRemark
-verbose:class
-XX:+HeapDumpOnOutOfMemoryError
-XX:ErrorFile=/data/logs/hs_err_pid%p.log
-Xloggc:/dev/shm/gc/gc.log
-XX:HeapDumpPath=/data/logs/
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintClassHistogramBeforeFullGC
-XX:+PrintClassHistogramAfterFullGC
-XX:+PrintCommandLineFlags
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintTenuringDistribution
-XX:+PrintHeapAtGC
4G内存 web应用 & 并发较低的应用
-Xms2048M
-Xmx2048M
-Xmn1024M
-XX:MetaspaceSize=256M
-XX:MaxMetaspaceSize=256M
-XX:+UseConcMarkSweepGC
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=70
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses
-XX:+CMSClassUnloadingEnabled
-XX:+ParallelRefProcEnabled
-XX:+CMSScavengeBeforeRemark
-verbose:class
-XX:+HeapDumpOnOutOfMemoryError
-XX:ErrorFile=/data/logs/hs_err_pid%p.log
-Xloggc:/dev/shm/gc/gc.log
-XX:HeapDumpPath=/data/logs/
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintClassHistogramBeforeFullGC
-XX:+PrintClassHistogramAfterFullGC
-XX:+PrintCommandLineFlags
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintTenuringDistribution
-XX:+PrintHeapAtGC
4G内存 job型应用
-Xms1536M
-Xmx1536M
-Xmn768M
-XX:MetaspaceSize=256M
-XX:MaxMetaspaceSize=256M
-XX:+UseConcMarkSweepGC
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=70
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses
-XX:+CMSClassUnloadingEnabled
-XX:+ParallelRefProcEnabled
-XX:+CMSScavengeBeforeRemark
-verbose:class
-XX:+HeapDumpOnOutOfMemoryError
-XX:ErrorFile=/data/logs/hs_err_pid%p.log
-Xloggc:/dev/shm/gc/gc.log
-XX:HeapDumpPath=/data/logs/
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintClassHistogramBeforeFullGC
-XX:+PrintClassHistogramAfterFullGC
-XX:+PrintCommandLineFlags
-XX:+PrintGCApplicationConcurrentTime
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintTenuringDistribution
-XX:+PrintHeapAtGC