title: What happens if System.exit() is called again while a JVM shutdown is already in progress?
body: <p>Is it no-op? Does the JVM avoid calling the shutdown hooks again?</p>
  
  <p>For a use case, consider an UncaughtExceptionHandler that calls System.exit() for SomeException and then SomeException is thrown in two separate threads within a short period of time.</p>
  
  <p>Also, assume that System.exit() is called in a new thread to avoid potential deadlocks.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>As one of the comments rightfully pointed out, I should have tested this myself but I was lazy. The test below completes successfully irrespective of whether System.exit() is called in a regular or daemon thread and exits with code 1 after printing:</p>
  
  <pre><code>Requesting shutdown ...
  Shutdown started ...
  Requesting shutdown ...
  Shutdown completed ...
  </code></pre>
  
  <p>And here is the code:</p>
  
  <pre><code>public class ConcurrentSystemExit {
  
    private final static boolean DAEMON = false;
  
    public static void main(String[] args) throws InterruptedException {
  
      // Register a shutdown hook that waits 6 secs
      Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
          try {
            System.out.println("Shutdown started ...");
            Thread.sleep(6000);
            System.out.println("Shutdown completed ...");
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      });
  
      // Define a Thread that calls exit()
      class ShutdownThread extends Thread {
        public void run() {
          System.out.println("Requesting shutdown ...");
          System.exit(1);
        }
      }
  
      // Issue first exit()
      Thread t1 = new ShutdownThread();
      t1.setDaemon(DAEMON);
      t1.start();
  
      Thread.sleep(3000);
  
      // Issue second exit()
      Thread t2 = new ShutdownThread();
      t2.setDaemon(DAEMON);
      t2.start();
    }
  }
  </code></pre>