如何在google appengine中实现shutdown hook handler。我在这里不了解他们的文件https://developers.google.com/appengine/docs/java/backends/overview#Shutdown。我需要的是,当后端由于任何原因而停止时,我需要在代码中得到通知。
this is my code
try{
while (haveMoreWork() &&
!LifecycleManager.getInstance().isShuttingDown()) {
process(); // this is my function to read all the data.if it fails because of termination.i need to be notified.
}catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
log.severe("error occured"+e);
log.info("failed ");
}
答案 0 :(得分:0)
您需要使用挂钩而不是状态报告:
LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
public void shutdown() {
// code
}
});