Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:52:59+00:00 2026-06-11T01:52:59+00:00

How can i create a heap dump from within my application, without using the

  • 0

How can i create a heap dump from within my application, without using the class HotSpotDiagnosticMXBean.
Due to access restriction of java/rt.jar i am not able to compile it with a dependency to HotSpotDiagnosticMXBean. I know how solve the eclipse.compiler error, but how can i fix it for my build?
Is there an alternative to way to create a heap dump programmatically?

  • This solution doesn’t work, because of it’s HotSpotDiagnosticMXBean dependency: HotSpot-dependent Heap Dump
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:53:00+00:00Added an answer on June 11, 2026 at 1:53 am

    Okay,seems like you can bypass the restriction by using reflection :

    package lab.heapdump;
    
    import javax.management.MBeanServer;
    import java.lang.management.ManagementFactory;
    import java.lang.reflect.Method;
    
    
    @SuppressWarnings("restriction")
    public class HeapDump {
        // This is the name of the HotSpot Diagnostic MBean
        private static final String HOTSPOT_BEAN_NAME =
             "com.sun.management:type=HotSpotDiagnostic";
    
        // field to store the hotspot diagnostic MBean 
        private static volatile Object hotspotMBean;
    
        /**
         * Call this method from your application whenever you 
         * want to dump the heap snapshot into a file.
         *
         * @param fileName name of the heap dump file
         * @param live flag that tells whether to dump
         *             only the live objects
         */
        static void dumpHeap(String fileName, boolean live) {
            // initialize hotspot diagnostic MBean
            initHotspotMBean();
            try {
                Class clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
                Method m = clazz.getMethod("dumpHeap", String.class, boolean.class);
                m.invoke( hotspotMBean , fileName, live);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception exp) {
                throw new RuntimeException(exp);
            }
        }
    
        // initialize the hotspot diagnostic MBean field
        private static void initHotspotMBean() {
            if (hotspotMBean == null) {
                synchronized (HeapDump.class) {
                    if (hotspotMBean == null) {
                        hotspotMBean = getHotspotMBean();
                    }
                }
            }
        }
    
        // get the hotspot diagnostic MBean from the
        // platform MBean server
        private static Object getHotspotMBean() {
            try {
                Class clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
                MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                Object bean = 
                    ManagementFactory.newPlatformMXBeanProxy(server,
                    HOTSPOT_BEAN_NAME, clazz);
                return bean;
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception exp) {
                throw new RuntimeException(exp);
            }
        }
    
        public static void main(String[] args) {
            // default heap dump file name
            String fileName = "D:\\heap.bin";
            // by default dump only the live objects
            boolean live = true;
    
            // simple command line options
            switch (args.length) {
                case 2:
                    live = args[1].equals("true");
                case 1:
                    fileName = args[0];
            }
    
            // dump the heap
            dumpHeap(fileName, live);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am analyzing a heap dump using a jvisualvm. From the report I can
In c++ you can create new instances of a class on both the heap
Can I use jmap to create a java memory heap on a JVM which
Is there any tool such that it can get a heap dump from a
I am trying to create a Max-Heap in java using the following code: public
How can I create a circular buffer on the heap in VB.NET ? This
How can create a New user in ORACLE with full access (alter, delete, select,
Can I create an object of my class in stack regarding .net and C#?
Is there a way to create a class Foo so that I can do:
How can I hide parts of a class so that whoever is using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.