天天看点

OutOfMemory问题定位

内存溢出定位

程序加入启动参数

​-Xms30M -Xmx30M -XX:+HeapDumpOnOutOfMemoryError​

加入下面代码

while (true) {
      //0.5M
      byte[] chars = new byte[1024 * 512];
      list.add(chars);
      Thread.sleep(1500);
    }      

OOM时会打印java_pidxxxx.hprof的dump文件

OutOfMemory问题定位

jvisualvm 打开 hprof文件,在概要->堆转储上的线程 可以定位到相应的方法和变量类型

OutOfMemory问题定位
"main" prio=5 tid=1 TIMED_WAITING
    at java.lang.Thread.sleep(Native Method)
    at com.xhx.spring.springoom.SpringOomApplication.afterPropertiesSet(SpringOomApplication.java:26)
       Local Variable: byte[]#34062