JVM-001-环境搭建及一个小例子
2017-11-22 本文已影响1人
53b3f4658edc
安装JDK
请查看这篇文章:认识JDK并配置path环境变量
一个内存泄漏分析的小例子
编写内存泄漏的代码
package top.itcourse.oom;
import java.util.ArrayList;
public class TestOOM {
public static void main(String[] args) {
List<Test> list = new ArrayList<>();
while (true) {
list.add(new Test());
}
}
}
class Test {
private String[] names = new String[1000*1000*1000];
}
运行上面的程序,打开jconsole

观测内存折线图

抓取内存快照
在运行的配置中输入如下参数:-XX:+HeapDumpOnOutOfMemoryError -Xms20m -Xmx20m

安装Eclipse Memory Analyzer
http://www.eclipse.org/mat/downloads.php
再次运行程序,并打开.hprof文件


其它
关注下方微信公众号,
回复:
JVM.code
-
欢迎加入交流群:451826376
-
更多信息:www.itcourse.top