title: Best Way to Gracefully Shutdown a Java Command Line Program
body: <p>I'm interested in different approaches to gracefully shutting down a Java command line program.  Sending a kill signal is not an option.</p>
  
  <p>I can think of a few different approaches.</p>
  
  <ol>
  <li>Open a port and wait for a connection.  When one is made, gracefully shutdown.</li>
  <li>Watch for a file to be created, then shutdown.</li>
  <li>Read some input from the terminal, such as "execute shutdown".</li>
  </ol>
  
  <p>The third one is not ideal, since there is often program output pumped to the screen.  The first one takes too much effort (I'm lazy).  Do most programmers use the second option?  If not, what else is possible/elegant/simple?</p>