+ private void delayedShutdown(int exitCode, long delayMs) {
+ LOGGER.info("Started delayed shutdown with delay {} ms.", delayMs);
+ Thread shutdownThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(delayMs);
+ LOGGER.warn("Delayed shutdown forced the application to exit with code {}.", exitCode);
+ // Method halt is used instead of System.exit, because running
+ // of shutdown hooks hangs the application in some cases.
+ Runtime.getRuntime().halt(exitCode);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ shutdownThread.setDaemon(true);
+ shutdownThread.setName("delayed-shutdown");
+ shutdownThread.start();
+ }
+