As we have http timeouts inside our cluster, it seems that due to this there is a connection leak. I investigated and connection remains always active.
The solution for me was to enable abandoned connections verification.
private DataSource configureDataSource(String url, String user, String password, String driverClassName){
DataSource ds = DataSourceBuilder.create()
.url(url)
.username(user)
.password(password)
.driverClassName(driverClassName)
.build();
org.apache.tomcat.jdbc.pool.DataSource configuredDataSource = (org.apache.tomcat.jdbc.pool.DataSource) ds;
// some other configurations here
// ...
configuredDataSource.getPoolProperties()
.setRemoveAbandonedTimeout(300);
configuredDataSource.getPoolProperties()
.setRemoveAbandoned(true);
}
@Bean(name = "qaDataSource")
public JdbcTemplate getQaJdbcTemplate() {
DataSource ds = configureDataSource(qaURL, qaUsername, qaPassword ,qaDriverClassName);
return new JdbcTemplate(ds);
}
RemoveAbandoned
and RemoveAbandonedTimeout
flags mean that if some connection is in active state more that timeout value it will be closed. If you put this to your code ensure that this timeout is superior that the maximum query execution time for your service.