Web 应用程序停止时停止 Apache Tomcat

编程入门 行业动态 更新时间:2024-10-23 01:57:31
本文介绍了Web 应用程序停止时停止 Apache Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

场景:

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 03:44:39,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   Web   Tomcat   Apache

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!