Open sumeetpri opened 4 years ago
try to build a SingleConnectionDataSource
object and call destroy()
method finally ,your code may look like this:
Connection connection=dataSource.getConnection();
SingleConnectionDataSource singleConnectionDataSource=new SingleConnectionDataSource(connection,true);
JdbcTemplate jdbcTemplate=new JdbcTemplate(singleConnectionDataSource);
jdbcTemplate.execute("select * from user where id=1");
singleConnectionDataSource.destroy();
Hi @wanglunhui2012 ,
I tried your idea of having singleConnectionDataSource.destroy()
. It did not solve the problem as i could still able to see unclosed type in jProfile connection leak .
But when i tried with suppressClose = false
, jProfile shows no unclosed in connection leak
SingleConnectionDataSource singleConnectionDataSource=new SingleConnectionDataSource(connection,false);
Why suppressClose = true
is a problem and leak ?
I think this problem is nothing to do with HikariCP,your usage of SingleConnectionDataSource
is not correct.the official site of Spring,SingleConnectionDataSource indicate that the class will never close the connection.
I change the source code of SingleConnectionDataSource.destroy()
:
public void destroy() {
synchronized(this.connectionMonitor) {
this.closeConnection();
// append start
try {
this.connection.close();
}catch (Exception e){
e.printStackTrace();
}
// append end
}
}
the connect leak disappear.but this.connection.close();
is proxied and it just return null,do nothing.the sql show full processlist;
shows that the connection num is minimum-idle
we configure.i don't know how JProfile analysis the connection leak.
I am using HikariCP-3.4.2 with viertix.io and scala monix.
Using Hikari connection pool is created like
Data source pool is built like
val ds: HikariDataSource = HanaConnection.createDataSource(maxPoolSize = 40, poolName = "my-db-pool")
I have two different function called from api using vertx.io . noLeak function is getting the data source and building JDBC template and executes simple select statement . Jprofiler shows no connection leak . But another function build jdbctemplate using SingleConnectionDataSource , other function shows connection leak even i am closing the connection explicitly