gpt4 book ai didi

hibernate - 在 Tomcat 上有一个线程使用 Hibernate 和 C3p0 数据库

转载 作者:行者123 更新时间:2023-11-28 22:33:07 25 4
gpt4 key购买 nike

我正在使用 Hibernate 和 C3P0 来管理我的连接。我还有一个线程来做数据库操作。

问题是当我从 tomcat 取消部署我的 webapp 时,我的线程正确退出,但连接池仍然存在,mysql 中仍然有连接,我认为它们是由 C3P0 管理的。

有没有办法强制 C3P0 关闭所有这些连接?

谢谢

最佳答案

检查 PooledDataSource对象,它有一个名为 hardReset 的方法。它的规范说

Destroys all pooled and checked-out Connections associated with this DataSource immediately. The PooledDataSource is reset to its initial state prior to first Connection acquisition, with no pools yet active, but ready for requests.

我认为这应该满足您的要求。

关于hibernate - 在 Tomcat 上有一个线程使用 Hibernate 和 C3p0 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4992203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com