Java: Take action on process death?
<p>I am debugging a Java app, which frequently involves killing the process. I would like to do some cleanup before the app dies. Is there a way to catch the event and react accordingly? (Sort of like catching a <code>KeyboardInterrupt</code> in Python.</p>

<p><strong>Update</strong>: I tried adding this to <code>main()</code>, but it doesn't seem to be working:         </p>

<pre><code>Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                System.out.println("Closing...");
            }
        });
</code></pre>

<p>The code does not get run.</p>
