]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
HeapDumper: making it delete the dump tilfe if it already exists
authorErlend Kristiansen <erlenkr@ifi.uio.no>
Sun, 23 Feb 2014 10:40:05 +0000 (11:40 +0100)
committerErlend Kristiansen <erlenkr@ifi.uio.no>
Sun, 23 Feb 2014 10:40:05 +0000 (11:40 +0100)
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/utils/HeapDumper.java

index 7fc7174d6f18d991b8e943eb368c4c970cb50179..53680b5a61659453b95b00ab61f9b084643b1467 100644 (file)
@@ -1,5 +1,6 @@
 package no.uio.ifi.refaktor.utils;
 
+import java.io.File;
 import java.lang.management.ManagementFactory;
 
 import javax.management.MBeanServer;
@@ -7,7 +8,8 @@ import javax.management.MBeanServer;
 import com.sun.management.HotSpotDiagnosticMXBean;
 
 /**
- * Stolen from https://blogs.oracle.com/sundararajan/entry/programmatically_dumping_heap_from_java
+ * Most of the code and the idea stolen 
+ * from https://blogs.oracle.com/sundararajan/entry/programmatically_dumping_heap_from_java
  */
 public class HeapDumper {
     // This is the name of the HotSpot Diagnostic MBean
@@ -29,6 +31,9 @@ public class HeapDumper {
         // initialize hotspot diagnostic MBean
         initHotspotMBean();
         try {
+               File file = new File(fileName);
+               if (file.exists())
+                       file.delete();
             hotspotMBean.dumpHeap(fileName, live);
         } catch (RuntimeException re) {
             throw re;