title: java shut down hook not work?
body: <p>I develop java swing application that measure bandwidth traffic
  but i hope when pc became shut down the application save total send and recive 
  traffic to file.
  when i use shutdownhook in my code and shut down my pc
  the file not save!
  any body can help me?`
  i use java on win7_64</p>
  
  <pre><code>    public static void main(String[] args) throws AWTException, IOException, URISyntaxException, Exception {
  
          NewClass n=NewClass.getInstance();
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
          public void run() {
              try {
                      saveHistory();//save send and recive traffic to file
                      System.out.println(1);
  
              } catch (IOException ex) {
                  Logger.getLogger(BandWidthMeter.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }, "Shutdown-thread"));
     }    
  }
  
       void saveHistory() throws IOException{
           Date date=new Date();
           SimpleDateFormat format=new SimpleDateFormat("yyyy/MM/dd hh:mm");
           String format1 = format.format(date);
           //convert traffic to kiloByte
           double session_Send=(double)send/1024;
            double session_Recive=(double)recive/1024;
           String row=format1+"-"+String.valueOf(session_Send)+"-"+String.valueOf(session_Recive);
          try (FileWriter fw = new FileWriter(new File("src/bandwidthmeter/history.txt"),true)) {
              fw.append(row);
              fw.append("\n");
          }
          try ( //update total.properties
                  FileOutputStream out = new FileOutputStream("src/bandwidthmeter/total.properties")) {
              //convert traffic to megabyte
              double sessionSend=(double)send/1048576;
              double sessionRecive=(double)recive/1048576;
              totalSend+=sessionSend;
              totalRecive+=sessionRecive;
              prop.setProperty("totalSend",String.valueOf(totalSend));
              prop.setProperty("totalRecive",String.valueOf(totalRecive));
              prop.store(out,null);
              out.close();
          }
       }
  </code></pre>