Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way to handle this would be to register a <a href="http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29" rel="noreferrer">shutdown</a> hook. If you use (<strong>SIGINT</strong>) <code>kill -2</code> will cause the program to gracefully exit and run the shutdown hooks.</p> <blockquote> <p>Registers a new virtual-machine shutdown hook.</p> <p>The Java virtual machine shuts down in response to two kinds of events:</p> <ul> <li><p>The program exits normally, when the last non-daemon thread exits or when the exit (equivalently, System.exit) method is invoked, or</p></li> <li><p>The virtual machine is terminated in response to a user interrupt, such as typing ^C, or a system-wide event, such as user logoff or system shutdown.</p></li> </ul> </blockquote> <p>I tried the following test program on OSX 10.6.3 and on <code>kill -9</code> it did <strong>NOT</strong> run the shutdown hook, didn't think it would. On a <code>kill -15</code> it <strong>DOES</strong> run the shutdown hook every time.</p> <pre><code>public class TestShutdownHook { public static void main(final String[] args) throws InterruptedException { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Shutdown hook ran!"); } }); while (true) { Thread.sleep(1000); } } } </code></pre> <p>This is the documented way to write your own <a href="http://www.google.com/search?hl=en&amp;q=sun.misc.signalhandler" rel="noreferrer">signal handlers</a> that aren't shutdown hooks in Java. Be <a href="http://java.sun.com/products/jdk/faq/faq-sun-packages.html" rel="noreferrer">warned</a> that the <code>com.sun.misc</code> packages and are un-supported and may be changed or go away at any time and probably only exist in the Sun JVM.</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.
    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.
 

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