@Override
    public void stop() throws Exception {
        log.finer("Destroying application.");
        Application app;
        ApplicationInUseTracker applicationInUseTracker;
        synchronized (appLock) {
            app = application;
            applicationInUseTracker = this.applicationInUseTracker;
        }
        if (app == null || applicationInUseTracker == null) {
            return;
        }
        try {
            app.stop();
        } catch (Exception e) {
            log.log(Level.WARNING, "Exception thrown while deactivating application.", e);
        }
        synchronized (appLock) {
            application = null;
        }
        try (DeactivatedContainer deactivated = activateContainer(null)) { }
        synchronized (appLock) {
            this.applicationInUseTracker = null;
        }
        applicationInUseTracker.release();
        applicationInUseTracker.applicationInUseLatch.await();
        app.destroy();
    }
@author Simon Thoresen Hult
@author bjorncs
jdisc_core/src/main/java/com/yahoo/jdisc/core/ApplicationLoader.java