private void stopNext() {
        final Provider<Runnable> runnableProvider = stopPending.pollFirst();
        if (runnableProvider != null) {
            final Runnable runnable = runnableProvider.get();
            LOGGER.info("Lifecycle " + runnable.getClass().getSimpleName() + " shutting down");
            CompletableFuture
                    .runAsync(runnable)
                    .whenComplete((r, t) -> {
                        if (t != null) {
                            while (t instanceof CompletionException) {
                                t = t.getCause();
                            }
                            LOGGER.error(t.getMessage(), t);
                        }
                        stopNext();
                        stopRemaining.countDown();
                    });
        }
    }
Called when the application context is destroyed.
stroom-lifecycle/stroom-lifecycle-impl/src/main/java/stroom/lifecycle/impl/LifecycleService.java