1

如何从连接池中删除损坏的连接对象?使用 c3p0

在我的应用程序中,当数据库通信失败时,它显示异常。获得数据库连接后立即发送任何数据库请求,我得到同样的异常。获得数据库连接 30 秒后的任何请求都可以正常工作。那么如何删除断开的连接对象?

我的连接属性是:-

url=jdbc:mysql://db_host:db_port/db_name
driverClassName=db_driver_class_name
username=root
password=password
hibernate.platform=org.hibernate.dialect.MySQLDialect
initialPoolSize=5
minPoolSize=5
maxPoolSize=20
checkoutTimeout=1000
maxStatements=20
acquireRetryAttempts=1
acquireRetryDelay=10
maxIdleTime=1
acquireIncrement=0
maxConnectionAge=1
4

2 回答 2

0

c3p0 可以通过几种方式测试连接:

  • 退房时
  • 入住时
  • 定期

此处描述了配置:http ://www.mchange.com/projects/c3p0/#configuring_connection_testing

请注意,连接测试会增加一些开销,具体取决于您对获得的连接所做的工作量。

于 2012-07-18T11:46:26.680 回答
0

在您的配置中包含以下参数

<prop key="hibernate.c3p0.max_idle_time">6</prop>
   <prop key="hibernate.c3p0.max_idle_time_excess_connection">4</prop>
   <prop key="hibernate.c3p0.idle_connection_test_period">600</prop>
   <prop key="hibernate.c3p0.test_connection_on_checkout">true</prop>
   <prop key="hibernate.c3p0.preferred_test_query">SELECT 1;</prop>

希望这对你有用

于 2012-07-18T11:49:17.810 回答