在一次解决系统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是处在假死状态的,只能在服务瘫痪的时候为了解决问题来使用,否则会造成服务中断。

相关文章:

  • 2021-08-04
  • 2021-10-18
  • 2021-09-10
  • 2021-05-11
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
猜你喜欢
  • 2022-02-14
  • 2022-01-06
  • 2021-12-29
  • 2021-06-22
相关资源
相似解决方案