### Question:
ShutdownHook implements Runnable { @Override public void run() { logger.log(Level.INFO, "Clean shutdown of daemon threads initiated"); Map<Thread, StackTraceElement[]> threadsMap = Thread.getAllStackTraces(); threadsMap.keySet().parallelStream().forEach((thread) -> { DaemonThread daemon; if (thread instanceof DaemonThread && thread.isAlive()) { daemon = (DaemonThread) thread; daemon.requestShutdown(); } }); threadsMap.keySet().stream().forEach((thread) -> { DaemonThread daemon; if (thread instanceof DaemonThread && thread.isAlive()) { daemon = (DaemonThread) thread; logger.log(Level.INFO, "Waiting for {0} to exit...", daemon); try { daemon.join(500); } catch (InterruptedException ex) { System.out.println(ex.getLocalizedMessage()); } } }); logger.log(Level.INFO, "Clean shutdown of daemon threads completed"); } ShutdownHook(); @Override void run();  }### Answer:
@Test public void testRun() { try { System.out.println("run"); Thread instance = new Thread(new ShutdownHook()); instance.start(); instance.join(); instance = new Thread(new ShutdownHook()); DaemonThread daemon; daemon = new DaemonThread(() -> { try { Thread.sleep(10000); } catch (InterruptedException ex) { System.out.println("Sleep interrupted"); } }); daemon.start(); instance.start(); instance.join(); } catch(InterruptedException ex) { fail("Interrupted while shutting down all AbstractDaemon"); } }