Web 应用程序停止时停止 Apache Tomcat [英] Stop Apache Tomcat when web application stops

查看:43
本文介绍了Web 应用程序停止时停止 Apache Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

Apache Tomcat 6.0 在 Windows Server 2008 R2 上作为服务启动,使用包装器 (org.tanukisoftware.wrapper.WrapperStartStop) 使用 org.apache.catalina.startup.Bootstrap.在 Tomcat 启动过程中,也会启动一个 Web 应用程序.此 Web 应用程序需要连接到远程数据库并检查连接.如果数据库不可用,它会重试连接几次,然后在 x 次尝试后关闭.

Apache Tomcat 6.0 is started as a service on Windows Server 2008 R2 using a wrapper (org.tanukisoftware.wrapper.WrapperStartStop) which uses org.apache.catalina.startup.Bootstrap. In course of the Tomcat startup one web application is also started. This web application needs to connect to a remote database and check the connection. It retries to connect a couple of times if the database is not available and then shutsdown after x tries.

问题:

当数据库连接不可用时,我需要在 webapp 退出后停止 Apache Tomcat.

I need to stop Apache Tomcat after the webapp exits when the database connection is not available.

可能的解决方案:

  • 从 Web 应用程序中停止 Apache Tomcat(已尝试关闭端口,但由于连接被拒绝而无法正常工作 - 使用独立的 Java 应用程序工作)
  • 从 Web 应用程序内部调用外部 Java 应用程序
  • 将 Apache Tomcat 配置为在唯一的 Web 应用程序关闭时关闭 - 我找不到这样做的方法

有什么想法吗?也许是一种不同的方法?

Any ideas? Maybe a different approach?

问候

亚历山大

推荐答案

System.exit(0) 如果没有配置安全管理器,您的 web 应用程序中将关闭 Tomcat 实例.

System.exit(0) from within your webapp will shut down the Tomcat instance if there is no security manager configured.

在独立服务器上工作,不确定在作为 Windows 服务运行时是否工作.

Works from a standalone server, not sure whether it works when running as a Windows service.

尽管您可能想阅读以下内容:Calling System.exit() 在 Servlet 的 destroy() 方法中

though you might want to read this: Calling System.exit() in Servlet's destroy() method

这篇关于Web 应用程序停止时停止 Apache Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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