title: Setup ShutdownHook and exit application
body: <p>I have the following code: </p>
  
  <pre><code>public static void main(String[] args) {
  
      // login event
      String event = "login";
      System.out.printf("Handling event: %s %s\n",event,getCurrentLogin());
      sendMessage(event, getCurrentLogin());
  
      // logout or shutdown event
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
          @Override
          public void run() {
                  String event = "logout";
                  System.out.printf("Handling event: %s %s\n",event,getCurrentLogin());
                  sendMessage(event, getCurrentLogin());
          }
      }));
   }
  </code></pre>
  
  <p>It's a very simple program for logging user's login and logout. The problem is that the program exits when reaches the end of function main(). </p>
  
  <p>Am I using to the shutdown event hook correctly?
  I don't want to create a complex windows service, it must be a very simple application cause it will be used for remote connected windows sessions.</p>
  
  <p>Do you have any suggesion for background waiting for the login termination ?</p>