Note that there are some explanatory texts on larger screens.

plurals
  1. POjvm: is it possible to find out process is shutting down due to an OOM while in the shutdown hook?
    primarykey
    data
    text
    <p>I have a critical process running in java (1.6), with a registered shutdown hook. In some instance where I get a OOM issue (more details below about the issue), the process stops suddenly, I don't get any of my logs, my catch(Throable x) is not catching the exception. </p> <p>But the shutdown hook works. So if there was a way to know that the process is going to shutdown due to some nasty OOM, I could log necessary info before exiting.</p> <p>Is there a way to do this? </p> <p><strong>About the OOM</strong>: Not sure what is the exception because as I said it does not get caught. I know it's a OOM because I start the process with </p> <pre><code>-XX:+HeapDumpOnOutOfMemoryError </code></pre> <p>and I get a heap dump file. In other cases an exception is caught, and it's a ava.lang.OutOfMemoryError: GC overhead limit exceeded. But not sure it's always this case.</p> <p><strong>EDIT:</strong></p> <p>In case it is not clear: <strong>I am not trying to prevent the OOM as it can happen for valid reasons in some scenario, I just want to make sure it is clear in the app log files</strong></p> <p><strong>My question is</strong>: is it possible to find out process is shutting down due to an OOM while in the shutdown hook?</p> <p>I need to do this <strong>programatically</strong> and <strong>from the same process</strong>. </p> <p>For now the best approach is see if it exists a heap dump file java_pid_pid of process_.hprof (I know the pid) with recent date and deduce there was an OOM. I guess I could try Runtime.getRuntime().freeMemory() and report the issue if the memory available is very low, but not sure how reliable is that, maybe when the process is shutting down it has already released much memory, the approach above is best I think.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload