Package se.jiderhamn

Class HeapDumper


  • public class HeapDumper
    extends java.lang.Object
    Class that helps programatically dumping the heap. Heavily inspired by https://blogs.oracle.com/sundararajan/entry/programmatically_dumping_heap_from_java
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String HEAP_DUMP_EXTENSION
      Filename extension for heap dumps
      private static java.lang.String HOTSPOT_BEAN_NAME
      The name of the HotSpot Diagnostic MBean
      private static com.sun.management.HotSpotDiagnosticMXBean hotSpotDiagnosticMBean
      HotSpot diagnostic MBean
    • Constructor Summary

      Constructors 
      Constructor Description
      HeapDumper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void dumpHeap​(java.io.File file, boolean live)
      Dump the heap snapshot into a file.
      private static com.sun.management.HotSpotDiagnosticMXBean getHotSpotDiagnosticMBean()
      Get HotSpot diagnostic MBean
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • HOTSPOT_BEAN_NAME

        private static final java.lang.String HOTSPOT_BEAN_NAME
        The name of the HotSpot Diagnostic MBean
        See Also:
        Constant Field Values
      • HEAP_DUMP_EXTENSION

        public static final java.lang.String HEAP_DUMP_EXTENSION
        Filename extension for heap dumps
        See Also:
        Constant Field Values
      • hotSpotDiagnosticMBean

        private static volatile com.sun.management.HotSpotDiagnosticMXBean hotSpotDiagnosticMBean
        HotSpot diagnostic MBean
    • Constructor Detail

      • HeapDumper

        public HeapDumper()
    • Method Detail

      • dumpHeap

        public static void dumpHeap​(java.io.File file,
                                    boolean live)
                             throws java.lang.ClassNotFoundException
        Dump the heap snapshot into a file.
        Parameters:
        file - The file in which the dump will be stored
        live - Dump only live objects?
        Throws:
        java.lang.ClassNotFoundException
      • getHotSpotDiagnosticMBean

        private static com.sun.management.HotSpotDiagnosticMXBean getHotSpotDiagnosticMBean()
        Get HotSpot diagnostic MBean