title: Java shutdown hook call on windows shut down
body: <p>I have a situation in which I want to perform some task when the user signals the OS(in my case only Windows) to shutdown. </p>
  
  <p>I have tried using java shutdown hooks. The problem I face is that when I exit the program using <code>System.exit(0);</code>, the shutdown hooks are called but when I directly shutdown the computer, they aren't.</p>
  
  <p>This is the code I have used for the shutdown hooks-</p>
  
  <pre><code>Runtime.getRuntime().addShutdownHook(new JVMShutdownHook()); //in main method
  
  //within the main java class
  private static class JVMShutdownHook extends Thread {
  @Override
  public void run() {
     //perform tasks
  }
  }
  </code></pre>
  
  <p>Is there any way to interact with the OS(I'm assuming some native code) so that it allows my program to exit gracefully?</p>
  
  <p>Any help would be greatly appreciated.</p>