JVM常用参数

JVM常用参数

// 列出所有线程
jps -l

// 列出所有线程以及启动参数
jps -lv

// 生成线程dump文件
jstack -l 16783 > ./threaddump

// 查询线程dump日志
grep java.lang.Thread.State ./threaddump | awk '{print $2$3$4$5}' |sort |uniq -c

// 生成dump文件
jmap -dump:live,format=b,file=./log.hprof 10086
    
// 查看java参数
java -XX:+PrintFlagsFinal

//CMS参数
// 老年代内存使用率一旦超过70%就会执行CMS GC了   java_1.7 100% java_1.8 92%
https://blog.csdn.net/insomsia/article/details/91802923
CMSInitiatingOccupancyFraction=70 


// 吞吐量优先的应用 推荐使用 Parallel Scavenge(复制) + Parallel Old(标记整理)
-XX:+UseParallelOldGC  //使用Parallel Scavenge+Parallel Old
-XX:+UseParallelGC //使用Parallel Scavenge+Serial Old

// 低停顿 推荐使用 ParNew(复制算法)+Cms(标记清除算法)+Serial Old(cms的预备收集(标记整理))
// cms收集器对CPU资源比较敏感 默认开启垃圾回收的线程为 (CPUs+3)/4,使用CMS收集器,在垃圾回收时,至少会占用25%的CPU资源,对应cpu负载比较高的服务器,不推荐使用CMS
-XX:+UseConcMarkSweepGC  -XX:+UseParNewGC 

// 使用G1收集器 官方推荐 G1收集器推荐用于需要大堆(大小约为6 GB或更大)且GC延迟要求有限的应用(稳定且可预测的暂停时间低于0.5秒)
-XX:+UseG1GC

//java启动参数详解
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
// 是否禁止System.gc()
-XX:+DisableExplicitGC

// 启动参数模板
-Xms1800m -Xmx1800m -Xmn1200M -XX:SurvivorRatio=4 -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=92 -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSParallelInitialMarkEnabled -XX:+CMSScavengeBeforeRemark -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/usr/local/gclog/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/gclog/dump.hprof

-Xms900m -Xmx900m -Xmn700M -XX:SurvivorRatio=5 -XX:MetaspaceSize=192M -XX:MaxMetaspaceSize=192M -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=92 -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSParallelInitialMarkEnabled -XX:+CMSScavengeBeforeRemark -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/usr/local/gclog/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/gclog/dump.hprof
     
-Xms4096m -Xmx4096m -Xmn3072M -XX:SurvivorRatio=4 -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=92 -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSParallelInitialMarkEnabled -XX:+CMSScavengeBeforeRemark -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/usr/local/gclog/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/gclog/dump.hprof
    
// nohup后台启动完整参数myWeb.jar
nohup java -jar -Xms1800m -Xmx1800m -Xmn1200M -XX:SurvivorRatio=4 -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=92 -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSParallelInitialMarkEnabled -XX:+CMSScavengeBeforeRemark -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/usr/local/gclog/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/gclog/dump.hprof myWeb.jar >/dev/null 2>&1 &

// java visualvm 远程主机启动参数
nohup java -Dcom.sun.management.jmxremote.port=40124 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false  -Djava.rmi.server.hostname=192.168.0.254 -jar myWeb.jar > /dev/null 2>&1 &

// 查看gc日志(查看pid=10001的进程的gc日志 每1000毫秒中打印1次,打印10次)
jstat -gc 10001 1000 10    

你可能感兴趣的:(JVM学习笔记)