Message.java Source code

Java tutorial

Introduction

Here is the source code for Message.java

Source

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 runTime = Runtime.getRuntime();
            runTime.addShutdownHook(p);

            // remove the hook
            runTime.removeShutdownHook(p);

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

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