@Override public void run() { final ServiceContainer sc; final ControlledProcessState ps; synchronized (this) { down = true; sc = container; ps = processState; } try { if (ps != null) { ps.setStopping(); } } finally { if (sc != null) { SystemExiter.logBeforeExit(HostControllerLogger.ROOT_LOGGER::shutdownHookInvoked); final CountDownLatch latch = new CountDownLatch(1); sc.addTerminateListener( new ServiceContainer.TerminateListener() { @Override public void handleTermination(Info info) { latch.countDown(); } }); sc.shutdown(); // wait for all services to finish. for (; ; ) { try { latch.await(); break; } catch (InterruptedException e) { } } } } }
/** * Delegate to the exiter to (possibly) exit the VM gracefully. * * @param status */ public void exit(int status) { systemExiter.exit(status); }