title: Java Out of memory automatic heap dump file name
body: <p>I have several Java processes and I am trying to manage the heap dumps created when OOM error occur. When I say manage I mean</p>
  
  <ul>
  <li>name the heap dump differently, based on the originating process</li>
  <li>delete older heap dumps to preserve disk space</li>
  </ul>
  
  <p>When dumping heap on OOM with</p>
  
  <pre><code> -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp
  </code></pre>
  
  <p>the JVM creates a file with the following name java_pidXXXX.hprof in the specified /tmp folder (where XXXX is the PID of the process).
  Is there anyway to specify a different format where the PID and DATE are used to create the file name?
  After googling for an hour I tried myPrefix_$, {pid}, 'date'..etc.
  The only two things that work are </p>
  
  <ol>
  <li>not specify the file name and you get java_pidXXXX.hprof</li>
  <li>specify a static file name e.g. \tmp\OOM.hprof.</li>
  </ol>
  
  <p>if the \tmp folder doesn't exist it doesn't get created, nor the heap dump gets created.  </p>
  
  <p>The one idea that could use is to add a command on OOM error</p>
  
  <pre><code>-XX:OnOutOfMemoryError="doSomething.sh %p"
  </code></pre>
  
  <p>but I was trying to avoid it as I need to deploy the "doSomething.sh"</p>