【问题标题】:Java jmap -heap command gave OutOfMemoryErrorJava jmap -heap 命令给出了 OutOfMemoryError
【发布时间】:2015-09-16 07:06:08
【问题描述】:

我们定期运行 jmap -heap 命令来监控一个 tomcat 应用程序。然而,这是我们第一次遇到 OutOfMemoryError。

当我们在服务器级别监控内存时,大约有 110MB 可用。由于它只是监控,我们是否可以忽略这个时间,假设没有对应用程序造成任何损害并且该命令运行时服务器内存不足?

$ ./jmap -heap 13511
Attaching to process ID 13511, please wait...
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at sun.tools.jmap.JMap.runTool(JMap.java:179)
        at sun.tools.jmap.JMap.main(JMap.java:110)
Caused by: java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:597)
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.<init>(LinuxDebuggerLocal.java:210)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.setupDebuggerLinux(BugSpotAgent.java:816)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.setupDebugger(BugSpotAgent.java:518)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:493)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:332)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
        at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:39)

更新: 我们尝试再次运行 jmap -heap 并得到 java.lang.OutOfMemoryError: Cannot create GC thread。系统资源不足。

所以,问题似乎出在操作系统资源级别。

$ ./jmap -heap 13511
#
# A fatal error has been detected by the Java Runtime Environment:
#
# java.lang.OutOfMemoryError: Cannot create GC thread. Out of system resources.
#
#  Internal Error (gcTaskThread.cpp:38), pid=13162, tid=1104300352
#  Error: Cannot create GC thread. Out of system resources.
#
# JRE version: 6.0_18-b07
# Java VM: Java HotSpot(TM) 64-Bit Server VM (16.0-b13 mixed mode linux-amd64 )
# An error report file with more information is saved as:
# /data01/home/s618199/JAVA/jdk1.6.0_18/bin/hs_err_pid13162.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#
Aborted

【问题讨论】:

  • 如果您获得 OOM,您的应用程序将关闭,因此运行 jmap 以定期产生堆转储存在很大风险。 -XX:+HeapDumpOnOutOfMemoryError 是调试 OOM 的更好选择
  • @SameerNaik:我们只想监控内存,不想产生堆转储。我不知道 jmap -heap 选项是否会产生堆转储。
  • 看这个。 herongyang.com/Java-Tools/… 它确实会产生堆转储。要监控内存,您可以使用基于 jmx 的工具,例如 jconsole。
  • @SameerNaik:谢谢。我认为并非 jmap 的所有选项都会产生堆转储。如果 -heap 选项也产生堆转储,我将研究并停止使用 jmap 进行内存监控。由于生产环境的限制,我们无法使用 jconsole 或 jvisualm 进行监控。
  • 根据我的研究,只有 jmap -dump 选项会产生堆转储。参考:docs.oracle.com/javase/6/docs/technotes/tools/share/…

标签: java tomcat out-of-memory jmap


【解决方案1】:

这不是内存问题(即使它被报告为一个),而是操作系统资源问题:您无法创建更多线程。而且它似乎会影响 jmap 程序而不是 Tomcat。

【讨论】:

  • 谢谢。你说的对。我们现在无法使用 putty session 登录服务器。我们得到“-bash:fork:资源暂时不可用”。
  • 你知道 jmap -heap 选项是产生堆转储还是只是分析进程的内存并打印状态?
  • 它认为它只是打印一个摘要和状态。只有 jmap -dump 创建堆转储。
  • 是的,没错。非常感谢。我已经将评论添加到问题中。参考:docs.oracle.com/javase/6/docs/technotes/tools/share/…
猜你喜欢
  • 2015-01-18
  • 1970-01-01
  • 1970-01-01
  • 2014-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-04
相关资源
最近更新 更多