tomcat中的shutdown hook(必要)没有运行 [英] shutdown hook in tomcat (necessary) not running

查看:453
本文介绍了tomcat中的shutdown hook(必要)没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长期运行的cpu和数据库密集型线程(以低优先级运行),可以由我的tomcat应用程序通过管理员请求触发。

I have a long running cpu and database intensive thread (that runs at low priority) that can be fired off by my tomcat application by an administrator request.

I对此线程使用关闭挂钩,这样如果应用程序被强制停止,它可以在退出之前清理数据库状态。在独立模式下完美运行,使用control-C并在eclipse控制台中取消。

I use a shutdown hook for this thread, so that if the application is stopped forcefully, it can clean up the database state before exiting. Works in standalone mode perfectly, with control-C and canceling in eclipse console.

但是当在tomcat下运行时,以及当我执行时:

But when running under tomcat, and when I do a:

$ CATALINA_HOME / bin / shutdown.sh

$CATALINA_HOME/bin/shutdown.sh

我通过调试日志验证我的servlet contextDestroyed消息是由tomcat发送的,但对于这个线程,消息无法阻止它,重要的是我的关机挂钩永远不会触发。

I verified with debug logging that my servlet contextDestroyed message gets sent by tomcat, but for this thread, there is no way that message can stop it, and the important point is that my shutdown hook never fires.

我注意到其他人说使用contextDestroyed消息,但赢了对我有用,而且一些问题和答案暗示关闭钩子在tomcat中适用于它们。

I noticed other people saying use contextDestroyed message, but that won't work for me, and also some questions and answers imply that the shutdown hook works for them in tomcat.

我使用的是tomcat 6.0.35。

I am using tomcat 6.0.35.

推荐答案


我有一个长期运行的cpu和数据库密集型线程(以低优先级运行)可以被触发由我的tomcat应用程序通过管理员请求。

I have a long running cpu and database intensive thread (that runs at low priority) that can be fired off by my tomcat application by an administrator request.

为什么不运行这个进程外的而不是打扰t他是webapp,上下文事件,关闭钩子还是任何腐烂?

Why not run this out-of-process and not bother with the webapp, context events, shutdown hooks, or any of that rot?

关闭钩子是一个kludge,正如@StephenC所说,他们不会在你想要的时候开火他们来。

Shutdown hooks are a kludge, and as @StephenC says, they won't fire when you want them to.

这篇关于tomcat中的shutdown hook(必要)没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆