传送门
【JVM】一、JVM体系结构
【JVM】二、JVM垃圾收集器
【JVM】三、JVM内存溢出问题分析查看
【JVM】四、JVM优化-GC调优
上一篇:【JVM】二、JVM垃圾收集器
- 一、JVM参数类型
- 1、标准参数(Standard Options),在各个版本中都有,是比较稳定的,以-开头;
- 2、非标准化X参数(Non-Standard Options),在各个jvm版本中不一样,以-X开头,可以使用 java -X 查看;
- 3、非标准化XX参数,也是不稳定,在各个jvm版本中不一样,主要用于jvm调优和debug,以-XX开头;
- 二、内存溢出问题分析
- 1、堆内存溢出
- 2、非堆内存溢出
- 3、问题分析方法
- (1)自动导出内存溢出堆栈转存文件;
- (2)手动导出内存溢出堆栈转存文件;
- 三、线程问题监控
- 1、jstack 监控线程信息
- 连接远程tomcat
- (1)开启远程访问:
- (2)开启远程访问并开启认证:
- (3)也可以再可在/root/.bash_profile最后追加如下配置:
- jstatd连接配置
文档:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
1、标准参数(Standard Options),在各个版本中都有,是比较稳定的,以-开头;-help
-server
-client
-version
-classpath
Advanced Runtime Options
Advanced JIT Compiler Options
Advanced Serviceability Options
Advanced Garbage Collection Options
非标准化XX参数分两类:
- (1)boolean类型
-XX:[±] +表示启用,-表示禁用
比如:-XX:+UseG1GC - (2)非boolean类型
-XX:=
-XX:MaxGCPauseMillis=200
新生代、老年代
2、非堆内存溢出方法区、Metaspace元空间
3、问题分析方法 (1)自动导出内存溢出堆栈转存文件;-Xmx10m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:d:/logs/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=d:/logs/heapdump.hprof
有可能生成失败;
(2)手动导出内存溢出堆栈转存文件;- jmap命令
jmap -dump:format=b,file=d:/logs/heapdump2.hprof 8392
- MAT 工具:
Memory Analysis (dump文件) mat
下载:https://www.eclipse.org/mat/
直接解压即可使用,和eclipse一样;
案例分析,前者查看对象数据,后者查看对象占用的内存;
- 线程状态:
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr034.html#sthref31
- 监控本地及远程进程
监控本地tomcat
监控远程tomcat
监控普通java进程
visualvm
文档:https://visualvm.github.io/index.html
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8898 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.10.137"(2)开启远程访问并开启认证:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8899 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access"
复制并修改授权文件 JAVA_HOME/jre/lib/management下 jmxremote.access和jmxremote.password.template的模板文件,将两个文件复制到CATALINA_BASE/conf目录下 重命名jmxremote.password.template文件为jmxremote.password 修改CATALINA_BASE/conf/jmxremote.access 添加内容: monitorRole readonly controlRole readwrite 修改CATALINA_BASE/conf/jmxremote.password 添加内容: monitorRole 123456 controlRole 123456 赋权限 chmod 600 jmxremote.password(3)也可以再可在/root/.bash_profile最后追加如下配置:
export JAVA_OPTS="-Dcom.sun.management.jmxremote? -Dcom.sun.management.jmxremote.port=8899 -Dcom.sun.management.jmxremote.ssl=false? -Dcom.sun.management.jmxremote.authenticate=false? -Djava.rmi.server.hostname=192.168.10.137"
使上述配置生效:
source ~/.bash_profile
启动想要监控的java程序;
或者在 /etc/profile 文件中配置;
需要jdk支持,jre不支持;
新建文件jstatd.all.policy(可自定义文件名),内容如下:
grant codebase "file:/usr/local/jdk1.8.0_101/lib/tools.jar" {
permission java.security.AllPermission;
};
执行命令(文件名与上一步相同):
jstatd -J-Djava.security.policy=jstatd.all.policy?&
&后台启动,-J后面没有空格,查看1099端口是否正常开启;



