`

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,以下是它的一些基本配置,来源于官网:

maximum-active-time:

    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! Default is 5 minutes.

maximum-connection-count:

    The maximum number of connections to the database. Default is 15.

maximum-connection-lifetime:

    The maximum amount of time that a connection exists for before it is killed (milliseconds). Default is 4 hours.

maximum-new-connections:

    Deprecated. Use simultaneous-build-throttle instead.

minimum-connection-count:

    The minimum number of connections we will keep open, regardless of whether anyone needs them or not. Default is 5.

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

trace:
    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). Default is false.

verbose:
    Either false (quiet) or true (loud). Default is false.

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。
分析:
项目中proxool属性配置只是配置了最小及最大连接数,其他都没有配置,并且hibernate.connection.release_mode的设置为auto,后台也有比较多的定时任务时间相隔很短去操作数据库,导致连接很快就被用完,所以目前知道的是把hibernate.connection.release_mode属性配置为after_transaction即可,经过多次的测试之后,把hibernate.connection.release_mode改为after_transaction是能解决连接池数的问题的。回过头来想想只要在操作数据库完后,只要把连接及时关闭就可以解决连接池数用完的问题。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics