javacrash-dumpsjvm-crash

how to generate thread dump java on out of memory error



Solution

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

    Your question can be simplified into:

    and:

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

    Bonus: it works fine on 1.5 too :)

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

    You may want to look into this:

     e.getMessage();
    

    and this:

    Thread.getAllStackTraces();
    

    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).