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:
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)