`
regbin
  • 浏览: 55521 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

JAVA调优之工具:jmap+mat

阅读更多

用途:用来查找内存泄露
介绍
 
         Jmap:jdk自带,主要用来查看JVM各个代的内存情况或内存占用状况, 支持导出整个JVM内存信息
          MAT :Eclipse 内存分析工具:http://www.eclipse.org/mat
使用
1、dump出内存信息:jmap -dump:format=b,file=dump.bin pid
2、eclipse 安装好mat插件: http://download.eclipse.org/mat/1.0/update-site/
3、eclipse直接打开dump的文件:dump.bin(注意:eclipse 内存设置大一点)
4、mat工具的具体使用网上比较多,还是比较好使用。分析后的文件可以生成html格式的,方便离线使用

 

试验代码

public class OutOfMemory {
    private String str;
    public OutOfMemory(String str) {
        this.str = str;
    }
    public static void main(String[] args) throws InterruptedException {
        HashMap<Integer, OutOfMemory> map = new HashMap<Integer, OutOfMemory>();
        String s = "O";
        for (Integer i = 0; i < 100; i++) {
            s += s;
            OutOfMemory o = new OutOfMemory(s);
            map.put(i, o);
            Thread.sleep(2000);
            System.out.println(i);
        }
    }
}

 

运行:java –Xmx128m –Xms128m OutOfMemory






 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics