Skip to content

Instantly share code, notes, and snippets.

@omkardeshpande8
Last active March 23, 2020 22:29
Show Gist options
  • Save omkardeshpande8/dc4259a8aa7a726a4fe787d9ece8f44a to your computer and use it in GitHub Desktop.
Save omkardeshpande8/dc4259a8aa7a726a4fe787d9ece8f44a to your computer and use it in GitHub Desktop.
Shutdown sequence
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