Spring BasicDataSource重现池错误等待空闲对象的超时

时间:2012-10-15 21:06:44

标签: spring timeout connection-pooling spring-jdbc

使用java / Spring / Ibatis sqlserver是数据库,数据源是org.apache.commons.dbcp.BasicDataSource以下是源对象

<bean id="wssModelDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="net.sourceforge.jtds.jdbcx.JtdsDataSource"/>
    <property name="url" value="com.wss.jdbc.ConnectionUrl=jdbc:jtds:sqlserver://x-x2/x_control_QA;appName=wss;sendStringParametersAsUnicode=false;loginTimeout=20;socketTimeout=180"/>
    <property name="username" value="xxx"/>
    <property name="password" value="xxx"/>
    <property name="maxActive" value="10"/>
    <property name="maxWait" value="10000"/>
  </bean>

在日志文件中,我们发现以下异常。

--- Cause: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object]

堆栈跟踪如下

Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, general error
        at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:118)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
        at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy.invoke(TransactionAwareDataSourceProxy.java:210)
        at .prepareStatement(Unknown Source)
        at com.ibatis.sqlmap.engine.execution.SqlExecutor.prepareStatement(SqlExecutor.java:494)
        at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:176)
        at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
        at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
        ... 196 more
Caused by: java.lang.InterruptedException
        at java.lang.Object.wait(Native Method)
        at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1112)
        at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
        ... 204 more
2012-10-15 04:29:57,258 [Thread-2] INFO  [ConnectionManagerImpl.java:58] : user[] Stopping managed instances...
2012-10-15 04:29:57,444 [http-bio-8000-exec-81187] INFO  [LoggingInterceptor.java:42] : user[] uri[/wss/security/login_submit.html] took[6.612] seconds
2012-10-15 04:29:57,451 [http-bio-8000-exec-81182] ERROR [LoginSubmitAction.java:121] : user[] Exception logging in[
--- The error occurred in ibatis/control_core.xml.
--- The error occurred while executing query.

我正在尝试使用Jmeter http登录请求重现此错误,并使用用户凭据作为params,这使我能够成功登录,结果从控制器调用DAO层。

但问题是我尝试过3个Jmeter实例永远运行循环100个线程,但它没有重现问题?我怎么能快速重现这个问题?

1 个答案:

答案 0 :(得分:0)

我使用Jmeter我创建了httprequest请求登录参数并启动了5个JMeter实例。最后能够重现这个问题。