Last active
March 23, 2020 22:29
-
-
Save omkardeshpande8/dc4259a8aa7a726a4fe787d9ece8f44a to your computer and use it in GitHub Desktop.
Shutdown sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PipelineResult pres = pipeline.run(); | |
Thread waitThread = Thread.currentThread(); | |
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | |
try { | |
pres.cancel(); | |
waitThread.join(); | |
} catch (UnsupportedOperationException | IOException | InterruptedException e){ | |
logger.error("Graceful cleanup in response to shutdown request failed:",e); | |
} | |
})); | |
PipelineResult.State state = pres.waitUntilFinish(); | |
new Thread(() -> { | |
try { | |
LOGGER.info("Application Killer sleeping for {} ms", 30_000); | |
Thread.sleep(30_000); | |
} catch (Exception e) { /* ignore exception */ | |
} finally { | |
LOGGER.warn("Application Killer acting ..."); | |
Runtime.getRuntime().halt(HALTING_STATUS_CODE); | |
} | |
}, "Application Killer Thread") | |
.start(); | |
System.exit(appState); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment