gpt4 book ai didi

spring - C3P0 Spring Hibernate : Pool maxed out. 如何调试?

转载 作者:行者123 更新时间:2023-12-04 02:07:49 24 4
gpt4 key购买 nike

我在 Tomcat 上有一个 Spring Hibernate 应用程序。连接池为C3P0

我很快遇到来自 C3P0 的线程池已用尽警告。然后所有对 webapp 的请求都会挂起。

我仍然假设我在代码的某处遗漏了 @Transaction 注释。我想调试我的代码。

问题:是否可以通过代码访问连接池,以便在连接释放和未释放时进行调试?

更新:当前的 c3p0 配置:

<!-- Hibernate -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="jdbc:postgresql://localhost/ikoda01?useUnicode=true&#38;characterEncoding=utf8" />
<property name="user" value="xxxuser" />
<property name="password" value="xxxxx" />

<property name="acquireIncrement" value="2" />
<property name="minPoolSize" value="3" />
<property name="maxPoolSize" value="50" />
<property name="maxIdleTime" value="600" />
</bean>

最佳答案

Can I access the connection pool via code so I can debug when a connection is released and when it is not released?

Yes

您甚至不必编写代码,这是内置的。如果您将 c3p0 配置为调试连接泄漏,它只会将检查泄漏连接的代码路径的堆栈跟踪打印到您的日志中。

更新:

<property name="unreturnedConnectionTimeout" value="30" />
<property name="debugUnreturnedConnectionStackTraces" value="true" />

unreturnedConnectionTimeout 应使用的值取决于您的应用程序。它应该比连接的最长预期合法使用时间长,但不是越短,您就会越快收到有关泄漏的日志消息,并且您的应用程序将越顺利地解决它。对于大多数网络应用程序,上面显示的 30 秒是保守的,客户端不会等待大约 30 秒的响应,因此超时安全地表示连接泄漏。

关于spring - C3P0 Spring Hibernate : Pool maxed out. 如何调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41773676/

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