@@ -0,0 +1,847 @@
+import java.util.concurrent.Executors;%0Aimport java.util.concurrent.ScheduledExecutorService;%0Aimport java.util.concurrent.ScheduledFuture;%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class TestShutdownHooks %7B%0A%0A    private static int tick = 0;%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        Runtime.getRuntime().addShutdownHook(new MyHook());%0A%0A%09int period = 1;%0A%09int duration = 20;%0A%0A%09ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);%0A%0A%09Runnable task = () -%3E System.out.println(String.format(%22%25d/%25d%22, tick++, duration));%0A%09executor.scheduleAtFixedRate(task, 0, period, TimeUnit.SECONDS);%0A%0A%09TimeUnit.SECONDS.sleep(duration);%0A%09executor.shutdownNow();%0A    %7D%0A    %0A    private static class MyHook extends Thread %7B%0A        public void run() %7B%0A            System.out.println(%22Hook called.%22);%0A        %7D%0A    %7D%0A%7D%0A

add test java program