AtomikosSQLException:连接池耗尽 - 每当应用程序抛出异常时连接都会耗尽

时间:2016-11-11 06:39:48

标签: hibernate spring-data-jpa jta distributed-transactions atomikos

在我的spring mvc应用程序中,我使用Atomikos Transaction API(v3.9.3)和JPA(Hibernate作为供应商)。我有两个实体管理器连接到两个数据源。下面提供了一个数据源的配置。 我面临的一个问题是,每当我的应用程序抛出异常时,连接就会耗尽并且无法获得。当所有连接从池中耗尽时,我最终得到AtomikosSQLException:连接池耗尽。任何人都可以帮助我的配置中缺少什么? 在实现这一点时,我关注了这个博客:

http://fabiomaffioletti.me/blog/2014/04/15/distributed-transactions-multiple-databases-spring-boot-spring-data-jpa-atomikos/

这是我的数据源配置:

@Bean(name = "masterDataSource", initMethod = "init", destroyMethod = "close")
public DataSource masterDataSource() {
    final MysqlXADataSource mysqlXaDataSource = new MysqlXADataSource();
    mysqlXaDataSource.setUrl(Preconditions.checkNotNull(env.getProperty("dataSource.master.url")));
    mysqlXaDataSource.setPinGlobalTxToPhysicalConnection(true);
    mysqlXaDataSource.setUser(Preconditions.checkNotNull(env.getProperty("dataSource.username")));
    mysqlXaDataSource.setPassword(Preconditions.checkNotNull(env.getProperty("dataSource.password")));

    AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
    xaDataSource.setXaDataSource(mysqlXaDataSource);
    xaDataSource.setUniqueResourceName("ds_master");

    return xaDataSource;
}

这是堆栈跟踪:

Unable to acquire JDBC Connection [n/a] 2016-11-11 10:50:58,487com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:46)
at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:90)
at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:85)
at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:347)
at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:394)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:99)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:129)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,在Atomikos上似乎是一个问题,我通过将atomikos版本升级到4.0.6来解决,如果您是商业用户,可以尝试使用3.9.4