Class HeapDump


  • public class HeapDump
    extends Object
    Helper class for generating heap dumps. Based on idea from here: https://blogs.oracle.com/sundararajan/programmatically-dumping-heap-from-java-applications
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • DIAGNOSTIC_NAME

        public static final String DIAGNOSTIC_NAME
        the hotspot bean for generating the dump.
        See Also:
        Constant Field Values
      • DIAGNOSTIC_INSTANCE

        protected static com.sun.management.HotSpotDiagnosticMXBean DIAGNOSTIC_INSTANCE
        the singleton instance.
      • INSTANTIATED

        protected static boolean INSTANTIATED
        whether the bean has been instantiated.
    • Constructor Detail

      • HeapDump

        public HeapDump()
    • Method Detail

      • initDiagnosticBean

        protected static String initDiagnosticBean()
        Initializes the diagnostic bean if necessary.
        Returns:
        null if successful, otherwise error message
      • generate

        public static String generate​(File output,
                                      boolean live)
        Generates a heap dump.
        Parameters:
        output - the file to save it to (.hprof extension)
        live - whether to use only live or all objects
        Returns:
        null if successful, otherwise error message