void awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
   LOGGER.debugf("awaitTermination: %dms", unit.toMillis(timeout));
   synchronized (shutdownInitiated) {
     if (shutdownInitiated.get() == false) {
       LOGGER.debugf("shutdownInitiated.wait");
       shutdownInitiated.wait(2000);
     }
   }
   serviceContainer.awaitTermination(timeout == 0 ? Long.MAX_VALUE : timeout, unit);
 }
    private void exit() {

      if (serviceContainer != null) {
        try {
          serviceContainer.shutdown();

          serviceContainer.awaitTermination();
        } catch (RuntimeException rte) {
          throw rte;
        } catch (InterruptedException ite) {
          ite.printStackTrace();
          Thread.currentThread().interrupt();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
      if (controlledProcessStateService != null) {
        controlledProcessStateService.removePropertyChangeListener(processStateListener);
        controlledProcessStateService = null;
      }
      if (executorService != null) {
        try {
          executorService.shutdown();

          // 10 secs is arbitrary, but if the service container is terminated,
          // no good can happen from waiting for ModelControllerClient requests to complete
          executorService.awaitTermination(10, TimeUnit.SECONDS);
        } catch (RuntimeException rte) {
          throw rte;
        } catch (InterruptedException ite) {
          ite.printStackTrace();
          Thread.currentThread().interrupt();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }

      if (uninstallStdIo) {
        try {
          StdioContext.uninstall();
        } catch (IllegalStateException ignored) {
          // something else already did
        }
      }

      SystemExiter.initialize(SystemExiter.Exiter.DEFAULT);
    }
 @AfterClass
 public static void testServerStartupAndShutDown() throws Exception {
   container.shutdown();
   container.awaitTermination();
   Assert.assertTrue(container.isShutdownComplete());
 }