title: How do I implement graceful termination in Java?
body: <p>Say for instance I have my application running in a Linux terminal and I press "CTRL+C" on my keyboard to kill the process it will terminate the Java program.</p>
  
  <p>Is there any way to catch this "request" in my Java application so I can shut it down gracefully and release all resources/write logs. I have several different threads running if it makes a difference to the response.</p>
  
  <p>I know you have have an addShutDownHook, but as written in the Java documentation, it isn't called under certain circumstances, like the kill signal from "CTRL+C" in linux...are there any other ways?</p>
  
  <pre><code>Runtime.getRuntime().addShutdownHook(new Thread()
  {
      public void run ()
      {
          // TODO: implement graceful shutdown here.
      }
  });
  </code></pre>