Java tutorial
class Message extends Thread { public void run() { System.out.println("Bye."); } } public class Main { public static void main(String[] args) { try { // register Message as shutdown hook Runtime runTime = Runtime.getRuntime(); runTime.addShutdownHook(new Message()); } catch (Exception e) { e.printStackTrace(); } } }