我遇到关机代码问题。所以我做了一个最小的后端 servlet 来测试它。
任何人都知道关闭挂钩是否可靠!?
我的日志根本没有显示任何_ah/stop线……目前。
我怀疑这可能与日志消失有关,但希望得到确认。即ApiProxi.flushLogs()在关机模式下不起作用。
一个有趣的提示是,当我生气并复制了这条线(15次)时......
log.info("LIFECYCLE - Shutdown hook invoked");
...我看到了_ah/stop线。
@Override
public void destroy() {
super.destroy();
log.info("LIFECYCLE - Shutting down");
ApiProxy.flushLogs();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
log.info("doGet()");
ApiProxy.flushLogs();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
log.info("doPost()");
ApiProxy.flushLogs();
}
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
log.info("LIFECYCLE - Starting up");
ApiProxy.flushLogs();
LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
public void shutdown() {
log.info("LIFECYCLE - Shutdown hook invoked");
ApiProxy.flushLogs();
}
});
}
@Override
public void destroy() {
super.destroy();
log.info("LIFECYCLE - Shutting down");
ApiProxy.flushLogs();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
log.info("doGet()");
ApiProxy.flushLogs();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
log.info("doPost()");
ApiProxy.flushLogs();
}