Dump heap programatically

This is one way you can dump the heap of a running JVM from within a page. This is not something you would place in a running production system, as you don’t want random GET’s to keep dumping the heap to disk. This is just another tool to add to your box for how to get things done under pressure.

<%@page import="javax.management.MBeanServer"%>
<%@page import="java.lang.management.ManagementFactory"%>
<%@page import="com.sun.management.HotSpotDiagnosticMXBean"%>

<%
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server,"com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
bean.dumpHeap("/u01/app/oracle/Middleware/mydump", true);
%>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.