Runtime: addShutdownHook(Thread hook) : Runtime « java.lang « Java by API






Runtime: addShutdownHook(Thread hook)

 
public class MainClass {
  public static void main(String[] args) throws Exception {
    Object f = new Object() {
      public void finalize() {
        System.out.println("Running finalize()");
      }
    };
    Runtime.getRuntime().addShutdownHook(new Thread() {
      public void run() {
        System.out.println("Running Shutdown Hook");
      }
    });

    f = null;
    System.gc();

    System.out.println("Calling System.exit()");
    System.exit(0);
  }
}

           
         
  








Related examples in the same category

1.Runtime: availableProcessors()
2.Runtime: exec(String[] command)
3.Runtime: exec(String command) (2)
4.Runtime: freeMemory()
5.Runtime: gc()
6.Runtime.getRuntime()
7.Runtime: maxMemory()
8.Runtime: totalMemory()