美文网首页JavaWeb
JVM-001-环境搭建及一个小例子

JVM-001-环境搭建及一个小例子

作者: 53b3f4658edc | 来源:发表于2017-11-22 17:34 被阅读1次

安装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

微信公众号:JavaWeb架构师

观测内存折线图


微信公众号:JavaWeb架构师

抓取内存快照

在运行的配置中输入如下参数:-XX:+HeapDumpOnOutOfMemoryError -Xms20m -Xmx20m


微信公众号:JavaWeb架构师

安装Eclipse Memory Analyzer

http://www.eclipse.org/mat/downloads.php


再次运行程序,并打开.hprof文件

微信公众号:JavaWeb架构师 微信公众号:JavaWeb架构师

其它



源码下载:

关注下方微信公众号,
回复:
JVM.code
完整教程PDF版本下载

相关文章

网友评论

    本文标题:JVM-001-环境搭建及一个小例子

    本文链接:https://www.haomeiwen.com/subject/ovdovxtx.html