Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, is your application ending or are you forcibly ending it? If you are forcibly ending it (via the stop button), this <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016" rel="noreferrer">Eclipse bug report</a> has details about why this might not be working.</p> <p>Failing that, you may be correct about this being Windows-specific behavior. I'm on a Mac so I can't confirm, sorry. However, I can tell you that the following test program <em>does</em> execute the shutdown hooks as expected.</p> <pre><code>public class MyShutdownHook { public static void main( String[] args ) { System.out.println( "Entering main." ); Runtime.getRuntime().addShutdownHook( new Thread( new Runnable() { public void run() { System.out.println( "Shutdown hook ran." ); } } ) ); System.out.println( "Exiting main." ); } } </code></pre> <p>The Javadocs for <a href="http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)" rel="noreferrer">Runtime#addShutdownHook</a> do mention that shutdown hooks do not run when the JVM is aborted, not exited normally, so again, you are probably correct in your assumptions. That being said, here are some things to try. Again, sorry I can't confirm these ahead of time -- no Windows here. (Blessedly!)</p> <ul> <li>Make sure the JVM does not include the <strong>-Xrs</strong> option. This has a <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html" rel="noreferrer">side-effect</a> on shutdown hooks.</li> <li>Try launching the JVM using either the <strong>-server</strong> or <strong>-client</strong> option. It's been my experience that edge-case behavior can be effected by the choice of VM mode. (Especially with regard to threading -- at least on Mac.)</li> <li>Are you launching your app under a profiler or the like? Loading any native libraries?</li> <li>Are you getting some fatal error and missing it? E.g., OutOfMemoryError or the like?</li> <li>Try checking/unchecking the <strong>Launch in background</strong> option from your application's <em>Run Configuration</em> dialog in Eclipse.</li> <li>Last but not least: Invoke <strong>System.exit()</strong> manually if you have the opportunity. :)</li> </ul>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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