AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@7b3106ec)

本文详细解析了DBCP连接池中的removeAbandoned、logAbandoned、removeAbandonedTimeout及maxWait等关键参数的作用与配置建议,并提供了一个具体的配置示例。

在有数据库操作的 Controller 的方法的前后都添加

System.out.println

在控制台中会看到两个输出中间多了一部分信息:

AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@7b3106ec)
   LogAbandoned: true
   RemoveAbandoned: true
   RemoveAbandonedTimeout: 10

这是一个日志信息,由dbcp连接池输出。

在配置时,主要难以理解的主要有:removeAbandoned 、logAbandoned、removeAbandonedTimeout、maxWait这四个参数,设置了rmoveAbandoned=true 那么在getNumActive()快要到getMaxActive()的时候,系统会进行无效的Connection的回收,回收的 Connection为removeAbandonedTimeout(默认300秒)中设置的秒数后没有使用的Connection,激活回收机制好像是getNumActive()=getMaxActive()-2。 有点忘了。 
  logAbandoned=true的话,将会在回收事件后,在log中打印出回收Connection的错误信息,包括在哪个地方用了Connection却忘记关闭了,在调试的时候很有用。 
  在这里私人建议maxWait的时间不要设得太长,maxWait如果设置太长那么客户端会等待很久才激发回收事件。 
  以下是我的配置的properties文件: 
#连接设置 
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver 
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:DBSERVER 
jdbc.username=user 
jdbc.password=pass 


#<!-- 初始化连接 --> 
dataSource.initialSize=10 


#<!-- 最大空闲连接 --> 
dataSource.maxIdle=20 


#<!-- 最小空闲连接 --> 
dataSource.minIdle=5 


#最大连接数量 
dataSource.maxActive=50 


#是否在自动回收超时连接的时候打印连接的超时错误 
dataSource.logAbandoned=true 


#是否自动回收超时连接 
dataSource.removeAbandoned=true 


#超时时间(以秒数为单位) 
dataSource.removeAbandonedTimeout=180 


#<!-- 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒 --> 
dataSource.maxWait=1000 






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值