java.sql.SQLException: Couldn't get connection because we are at maximum connect

java.sql.SQLException: Couldn't get connection because we are at maximum connection count (30/30) and there are none available报错,项目中实际碰到过。下面先讲讲所用到数据库连接池proxool,以下是它的一些基本配置,来源于官网:

[b] maximum-active-time:[/b]

If the housekeeper comes across a thread that has been active for longer than this then it will kill it. So make sure you set this to a number bigger than your slowest expected response! [color=red]Default is 5 minutes[/color].

[b]maximum-connection-count:[/b]

The maximum number of connections to the database. [color=red]Default is 15[/color].

[b]maximum-connection-lifetime:[/b]

The maximum amount of time that a connection exists for before it is killed (milliseconds). [color=red]Default is 4 hours[/color].

[b]maximum-new-connections:[/b]

Deprecated. Use simultaneous-build-throttle instead.

[b]minimum-connection-count:[/b]

The minimum number of connections we will keep open, regardless of whether anyone needs them or not. [color=red]Default is 5[/color].

[b]overload-without-refusal-lifetime:[/b]
This helps us determine the pool status. If we have refused a connection within this threshold (milliseconds) then we are overloaded. [color=red]Default is 60 [/color]seconds.

[b]trace:[/b]
If true then each SQL call gets logged (DEBUG level) along with the execution time. You can also get this information by registering a ConnectionListener (see ProxoolFacade).[color=red] Default is false[/color].

[b]verbose:[/b]
Either false (quiet) or true (loud). [color=red]Default is false[/color].

java.sql.SQLException: Couldn't get connection because we are at maximum connection count (30/30) and there are none available,从所给的信息上看,说的是数据库连接数已被消耗完,由于连接为及时释放,因为proxool结合hibernate使用,hibernate的属性hibernate.connection.release_mode,hibernate.connection.release_mode
指定 Hibernate 在何时释放 JDBC 连接。默认情况下,直到 Session 被显式关闭或被断开连接时,才会释放 JDBC 连接。对于应用程序服务器的 JTA 数据源,你应当使用 after_statement,这样在每次 JDBC 调用后,都会主动的释放连接。对于非 JTA 的连接,使用 after_transaction 在每个事务结束时释放连接是合理的。auto 将为 JTA 和 CMT 事务策略选择 after_statement,为JDBC事务策略选择 after_transaction。
例如:auto (默认) | on_close | after_transaction | after_statement。
[b]分析:
项目中proxool属性配置只是配置了最小及最大连接数,其他都没有配置,并且hibernate.connection.release_mode的设置为auto,后台也有比较多的定时任务时间相隔很短去操作数据库,导致连接很快就被用完,所以目前知道的是把hibernate.connection.release_mode属性配置为after_transaction即可,经过多次的测试之后,把hibernate.connection.release_mode改为after_transaction是能解决连接池数的问题的。回过头来想想只要在操作数据库完后,只要把连接及时关闭就可以解决连接池数用完的问题。 [/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值