title: java shutdown hook with more than one thread
body: <p>I am trying to get a shutdown hook to work on my ubuntu server, however I seem to have an issue with more than one thread.  Using the a basic ShutdownHook, the following bit of code does work when I kill the process using <code>kill &lt;PID&gt;</code>, meaning the shutdown behavior is activated.</p>
  
  <pre><code>public static void main(String[] args) {
      ShutdownHook shutDown = new ShutdownHook();
      shutDown.attachShutDownHook();
  
      while(true){}
  }
  </code></pre>
  
  <p>however this same code with an additional thread does not</p>
  
  <pre><code>public static void main(String[] args) {
      ShutdownHook shutDown = new ShutdownHook();
      shutDown.attachShutDownHook();
  
      (new Thread() {
          public void run() {
              while ( true ) {}
          }
      }).start();
  
      while(true){}
  }
  </code></pre>
  
  <p>Any ideas?</p>
  
  <pre><code>class ShutdownHook {
  
      ShutdownHook() {
      }
  
      public void attachShutDownHook() {
  
              Runtime.getRuntime().addShutdownHook(new Thread() {
                      @Override
                      public void run() {
                              System.out.println("Shut down hook activating");
                      }
              });
              System.out.println("Shut Down Hook Attached.");
  
      }
  }
  </code></pre>