BAEL-2171 - java heap dumps

This commit is contained in:
Marcos Lopez Gonzalez 2018-09-13 22:37:40 +02:00
parent e8a4138d15
commit 597602a478

View File

@ -0,0 +1,23 @@
package com.baeldung.heapdump;
import com.sun.management.HotSpotDiagnosticMXBean;
import javax.management.MBeanServer;
import java.io.IOException;
import java.lang.management.ManagementFactory;
public class HeapDump {
public static void dumpHeap(String filePath, boolean live) throws IOException {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
HotSpotDiagnosticMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(
server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
mxBean.dumpHeap(filePath, live);
}
public static void main(String[] args) throws IOException {
final String file = "/tmp/dump.hprof";
dumpHeap(file, true);
}
}