我应该明确销毁用作 Tomcat 资源的连接池吗?

发布于 2024-12-08 16:59:53 字数 597 浏览 0 评论 0原文

我的项目是创建一个 Web 服务,它将连接到 XMPP 服务器并充当向 XMPP 客户端发送消息的桥梁(WS 调用 -> XMPP 消息)。最近,我考虑创建一个连接,该连接将在所有请求之间共享(->我之前的问题)。

但是,我被告知要创建一些更具可扩展性的东西,并考虑连接池。我在此处找到了一段非常有用的代码。但是,我担心 Tomcat 容器中的内存泄漏 - 我读了太多相关内容;)在这里,我有几个问题:

  1. 如果我将该库指定为资源,它会在上下文初始化期间自动创建。服务器关闭后内存泄漏怎么办?它们不会自动销毁,是吗?我知道我应该手动销毁它,创建一个 ContextListener,但是我应该调用什么?
  2. 如果我放入资源定义

    removeAbandoned =“true”removeAbandonedTimeout =“60”
    

    它有助于销毁池中的僵尸连接吗?这是一个正确的解决方案还是只是灾难后的一种恢复?

任何帮助将不胜感激,非常感谢!

My project is to create a webservice which would connect to a XMPP server and serve as a bridge to send messages to XMPP clients (WS calls -> XMPP messages). Recently, I thought about creating a single connection, which would be shared across all requests (-> my previous question).

But, I was told to create something which would be more scalable and to think about connection pooling. I found a very useful piece of code here. But, I am afraid of memory leaks in Tomcat container - I've read too much about it;) Here, I've got few questions:

  1. If I specify that library as a resource, it is automatically created during context initialization. What about memory leaks after e.g. server shutdown? They aren't destroyed automatically, are they? I understand that I should destroy it manually, creating a ContextListener, but what should I call?
  2. If I put into resource definition

     removeAbandoned="true" removeAbandonedTimeout="60"
    

    will it help to destroy zombie connections from the pool? Is it a correct solution or just a sort of recovering after a disaster?

Any help will be much appreciated, thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-12-15 16:59:54

如果关闭服务器,那么也就关闭了 JVM,资源泄漏就不再重要了。您可能读到的与 Tomcat 相关的唯一内存泄漏是PermGen 问题,这通常困扰着 webapp 开发。不用担心连接池。它会照顾好自己的。

If you shut down the server, then you're shutting down the JVM, and resource leaks won't matter. The only memory leaks you've likely read about in relation to Tomcat is the PermGen problem, which plagues webapp development in general. Don't worry about the connection pool. It'll take care of itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文