【问题标题】:How to implement shutdown hook handler in google appengine如何在 google appengine 中实现关闭挂钩处理程序
【发布时间】:2013-04-02 09:48:40
【问题描述】:

如何在 google appengine 中实现关闭挂钩处理程序。我不理解他们的文档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 ");
    }

【问题讨论】:

    标签: java google-app-engine


    【解决方案1】:

    你需要使用钩子而不是状态报告:

    LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
      public void shutdown() {
        // code
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-09
      相关资源
      最近更新 更多