title: Write JVM heap dump to stdout
body: <p>We are using the following JVM flags to run a Spring Boot app inside Docker (managed by Kubernetes)</p>
  
  <pre><code>-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:+ExitOnOutofMemoryError 
  </code></pre>
  
  <p>As expected, the container gets restarted upon an OOM exception. However, the heap dump created on exit (in <em>/tmp</em>) is no longer available as the container has been restarted. While we can map a persistent volume, is there a way in which we can have the heap dump written to STDOUT (as we already collect logs from STDOUT)? Using <code>-XX:HeapDumpPath=/dev/stdout</code> results in </p>
  
  <p>*</p>
  
  <pre><code>Dumping heap to /dev/stdout ...
  Unable to create /dev/stdout: File exists
  </code></pre>
  
  <p>*</p>
  
  <p>Is there a simple work-around that I am missing here?</p>