Skip to content

Commit 597602a

Browse files
committed
BAEL-2171 - java heap dumps
1 parent e8a4138 commit 597602a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.heapdump;
2+
3+
import com.sun.management.HotSpotDiagnosticMXBean;
4+
5+
import javax.management.MBeanServer;
6+
import java.io.IOException;
7+
import java.lang.management.ManagementFactory;
8+
9+
public class HeapDump {
10+
11+
public static void dumpHeap(String filePath, boolean live) throws IOException {
12+
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
13+
HotSpotDiagnosticMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(
14+
server, "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
15+
mxBean.dumpHeap(filePath, live);
16+
}
17+
18+
public static void main(String[] args) throws IOException {
19+
final String file = "/tmp/dump.hprof";
20+
21+
dumpHeap(file, true);
22+
}
23+
}

0 commit comments

Comments
 (0)