Java Runtime .removeShutdownHook ( Thread hook)

Syntax

Runtime.removeShutdownHook(Thread hook) has the following syntax.

public boolean removeShutdownHook(Thread hook)

Example

In the following code shows how to use Runtime.removeShutdownHook(Thread hook) method.


/*  www.j  a va  2s . co m*/
class Message extends Thread {

  public void run() {
    System.out.println("Bye.");
  }
}

public class Main {

  public static void main(String[] args) {
    try {
      Message p = new Message();
      // register Message as shutdown hook
      Runtime.getRuntime().addShutdownHook(p);

      // remove the hook
      Runtime.getRuntime().removeShutdownHook(p);

      System.out.println("Program is closing...");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable