3

In my spring mvc application, I am using Atomikos Transaction API (v3.9.3) with JPA (Hibernate as vendor). I have two entity managers connecting to two datasources. Configuration of one of the datasources is provided below. I am facing an issue that whenever my application is throwing exception, connection is getting exhausted and is not getting acquired. And when all the connections are exhausted from pool, i end up getting AtomikosSQLException: Connection pool exhausted. Can anyone please help what is missing in my configuration? While implementing this, I followed this blog:

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

Here's my Datasource configuration:

@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;
}

Here's the stack trace:

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)
  • Varenya, Do you able to find a solution to fix this issue? I think I am having the same issue as well. I am using atomikos 4.0.4, Spring 4.3.2 and hibernate 4.3.11. – kenn3th Feb 05 '17 at 18:48
  • Varenya and kenn3th did you manage to fix this ? – nanpakal Mar 23 '18 at 10:13

1 Answers1

0

I faced the same problem and it looks to be an issue on Atomikos and I resolved by upgrading the atomikos version to 4.0.6 and if you are a commercial user you can give a try with 3.9.4

Naveen
  • 360
  • 1
  • 8
  • 23