【问题标题】:com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on thecom.atomikos.jdbc.AtomikosSQLException:连接池已用尽 - 尝试增加“maxPoolSize”和/或“borrowConnectionTimeout”
【发布时间】:2021-06-09 08:35:04
【问题描述】:

在我的 spring 批处理应用程序中,我使用 atomikos 版本(4.0.4)和 JTA(1.1)。一些作业挂在 PROD 中并从 DB 获取所有连接,这反过来又停止了其他作业并行触发。并且所有都失败并出现以下错误。

Error Log 1:
Could not get JDBC Connection; nested exception is com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.

Error Log 2 :
Failed to grow connection pool.

And almost for 13 jobs no instance got created in DB and in control-m the logs were captured with "Null Exception Message intercepted"

有人可以就这个问题提出建议吗?甚至尝试将 atomikos 版本升级到 5.0.0 但仍然出现同样的问题。

 {

AtomikosDataSourceBean ads = new AtomikosDataSourceBean();

        if (mDevModeDriverClassName.toLowerCase().contains("oracle")) {
            if (!mDevModeDriverClassName.equals("oracle.jdbc.xa.client.OracleXADataSource")) {
                log.warn("DataSource property 'devModeDriverClassName' should be set "
                        + "to 'oracle.jdbc.xa.client.OracleXADataSource' when using Oracle! " + "Current value is: "
                        + mDevModeDriverClassName);
            }
        }
        String vUniqueResourceName = "DS-" + UUID.randomUUID();
        log.debug("Creating Oracle XA DataSource. uniqueResourceName={}"+vUniqueResourceName);
        ads.setUniqueResourceName(vUniqueResourceName);
        ads.setXaDataSourceClassName(mDevModeDriverClassName); // "oracle.jdbc.xa.client.OracleXADataSource");
        ads.setMaxPoolSize((mDevModeMaxSize > 0) ? mDevModeMaxSize : 1); //mDevModeMaxSize =10
        ads.setTestQuery("SELECT 1 FROM DUAL");      
        Properties xaProps = new Properties();
        xaProps.setProperty("user", mDevModeUsername);
        xaProps.setProperty("password", mDevModePassword);
        xaProps.setProperty("URL", mDevModeJdbcUrl);
        ads.setXaProperties(xaProps); 
        OracleXADataSource xaDataSource = new OracleXADataSource();
        xaDataSource.setUser(mDevModeUsername);
        xaDataSource.setPassword(mDevModePassword);
        xaDataSource.setURL(mDevModeJdbcUrl);
        ads.setXaDataSource(xaDataSource);

<bean id="rsDataSource" class="com.sample.CustomDataSource" scope="singleton" destroy-method="close">       
        <property name="devModeDriverClassName" value="${spring.datasource.driver-class-name}" />
        <property name="devModeJdbcUrl" value="${spring.datasource.rs.url}" />
        <property name="devModeUsername" value="${spring.datasource.rs.username}" />
        <property name="devModePassword" value="${spring.datasource.rs.password}" />
        <property name="devModeMaxSize" value="10" />  
    </bean> 
 <bean id="transactionManager"
          class="org.springframework.transaction.jta.JtaTransactionManager"  >
        <property name="nestedTransactionAllowed" value="true"/>
        <property name="allowCustomIsolationLevels" value="true"/>
        <property name="defaultTimeout" value="-1"/> 
        <property name="transactionManager"  ref="txManager"></property>
   </bean>
   
   <bean id="txManager" class="com.atomikos.icatch.jta.UserTransactionManager" destroy-method="close">
        <property name="forceShutdown" value="true"/>
        <property name="transactionTimeout" value="60"></property>
        
   </bean> 

【问题讨论】:

    标签: spring-batch atomikos


    【解决方案1】:

    您有连接泄漏或您的池大小配置不正确。查看您的配置,很可能您的连接池大小配置不正确:

    几乎 13 个作业没有创建实例

    ads.setMaxPoolSize((mDevModeMaxSize > 0) ? mDevModeMaxSize : 1); //mDevModeMaxSize =10

    &lt;property name="devModeMaxSize" value="10" /&gt;

    您的连接池设置为最多提供 10 个连接,但您正在启动 13 个作业。所以出现这个错误也就不足为奇了:

    Connection pool exhausted - try increasing 'maxPoolSize'
    

    您需要相应地增加maxPoolSize

    【讨论】:

    • 感谢您的建议。池大小是否取决于并行运行的作业数量?如何识别spring批处理应用中的连接泄漏问题?
    • 这取决于作业,但最低要求是每个作业将尝试获取至少一个连接。首先尝试增加池大小,它应该可以解决问题。
    猜你喜欢
    • 2020-07-08
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2012-06-14
    • 2022-01-26
    • 2019-03-10
    • 1970-01-01
    • 2017-07-10
    相关资源
    最近更新 更多