java内存溢出分析工具

http://www.cnblogs.com/preftest/archive/2011/12/08/2281322.html
java内存溢出分析工具:jmap使用实战


 
 
在一次解决系统tomcat老是内存撑到头,然后崩溃的问题时,使用到了jmap。
 1 使用命令
 在环境是linux+jdk1.5以上,这个工具是自带的,路径在JDK_HOME/bin/下
 jmap -histo pid>a.log
 
2 输出结果摘要
 Size    Count   Class description
 -------------------------------------------------------
 353371288       9652324 char[]
 230711112       9612963 java.lang.String
 139347160       114865  byte[]
 76128096        3172004 java.util.Hashtable$Entry
 75782280        3157595 com.test.util.IPSeeker$IPLocation
 25724272        9115    java.util.Hashtable$Entry[]
 9319968 166428  org.apache.tomcat.util.buf.MessageBytes
 8533856 32889   int[]
 
发现有大量的String和自定义对象com.test.util.IPSeeker$IPLocation存在,检查程序发现此处果然存在内存溢出。修改程序上线后再次用jmap抓取内存数据:
 
146881712   207163  byte[]
 98976352    354285  char[]
 42595272    53558   int[]
 11515632    479818  java.util.HashMap$Entry
 9521896 59808   java.util.HashMap$Entry[]
 8887392 370308  com.test.bean.UnionIPEntry
 8704808 155443  org.apache.tomcat.util.buf.MessageBytes
 8066880 336120  java.lang.String
 
内存溢出问题消除。
 注意:这个jmap使用的时候jvm是处在假死状态的,只能在服务瘫痪的时候为了解决问题来使用,否则会造成服务中断。

 

posted @ 2015-03-13 11:41  Agoly  阅读(1139)  评论(0编辑  收藏  举报