如何在内存不足错误时生成线程转储java [英] how to generate thread dump java on out of memory error

查看:99
本文介绍了如何在内存不足错误时生成线程转储java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 除了堆转储(java_pid14941.hprof)之外java 6还生成线程转储

  • does java 6 generate thread dump in addition to heap dump (java_pid14941.hprof)

这是什么发生在我的一个应用程序中。

this is what happened to one of my applications.

java.lang.OutOfMemoryError:GC开销限制超过
将堆转储到java_pid14941.hprof ...

java.lang.OutOfMemoryError: GC overhead limit exceeded Dumping heap to java_pid14941.hprof ...

我确实在工作目录中找到了ava_pid14941.hprof,但没有找到任何包含线程转储的文件。当我得到这个OutOfMemory错误时,我需要知道所有线程正在做什么。

I did find ava_pid14941.hprof in working directory, but didn't find any file which contains thread dump. I need to know what all the threads were doing when I got this OutOfMemory error.

是否有任何配置选项除了堆转储之外还会生成线程转储内存不足异常?

Is there any configuration option which will generate thread dump in addition to heap dump on out of memory exception?

推荐答案


如何在
内存错误中生成线程转储java?

How to generate thread dump java on out of memory error?

您的问题可以简化为:


  • 如何生成线程转储

和:


  • 如何捕获内存不足错误(不要在这里注意反对者,他们错过了更大的图片,请参阅我的评论)

所以它实际上非常简单,你可以这样做:

So it's actually quite easy, you could do it like this:


  • 安装默认的未捕获异常处理程序

  • install a default uncaught exception handler

捕获未捕获的异常时,检查是否有OutOfMemoryError

upon catching an uncaught exception, check if you have an OutOfMemoryError

如果你有OutOfMemoryError,生成一个完整的线程转储,并要求用户通过电子邮件发送给您或者提供自动发送

if you have an OutOfMemoryError, generate yourself a full thread dump and either ask the user to send it to you by email or offer to send it automatically

奖励:它也适用于1.5:)

Bonus: it works fine on 1.5 too :)

 Thread.setDefaultUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() {
     public void uncaughtException( final Thread t, final Throwable e ) {
         ...
     }

你可能想看看这个:

 e.getMessage();

这个:

Thread.getAllStackTraces();

我在数百种不同的1.5和1.6上运行的应用程序中一直这样做JVM(在不同的操作系统上)。

I'm doing this all the time in an app that is shipped on hundreds of different 1.5 and 1.6 JVM (on different OSes).

这篇关于如何在内存不足错误时生成线程转储java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆