File tree 1 file changed +25
-0
lines changed
core-java/src/main/java/com/baeldung/heapdump
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .heapdump ;
2
+
3
+ import com .sun .management .HotSpotDiagnosticMXBean ;
4
+
5
+ import javax .management .MBeanServer ;
6
+
7
+ import java .io .IOException ;
8
+ import java .lang .management .ManagementFactory ;
9
+ import java .nio .file .Paths ;
10
+
11
+ public class HeapDump {
12
+
13
+ public static void dumpHeap (String filePath , boolean live ) throws IOException {
14
+ MBeanServer server = ManagementFactory .getPlatformMBeanServer ();
15
+ HotSpotDiagnosticMXBean mxBean = ManagementFactory .newPlatformMXBeanProxy (
16
+ server , "com.sun.management:type=HotSpotDiagnostic" , HotSpotDiagnosticMXBean .class );
17
+ mxBean .dumpHeap (filePath , live );
18
+ }
19
+
20
+ public static void main (String [] args ) throws IOException {
21
+ String file = Paths .get ("dump.hprof" ).toFile ().getPath ();
22
+
23
+ dumpHeap (file , true );
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments