0

How to configure BasicDataSource so after ds.getConnection().close() connection really closed?

According to:

http://commons.apache.org/proper/commons-dbcp/api-1.4/org/apache/commons/dbcp/BasicDataSource.html#maxIdle

I need:

ds.setMaxIdle(0);
ds.setTimeBetweenEvictionRunsMillis(60*1000);

But I'm not sure...

gavenkoa
  • 45,285
  • 19
  • 251
  • 303

1 Answers1

1

Setting the max idle to 0, and setting the time between eviction runs to 60 seconds basically means that if you don't close the connection, the BasicDataSource will close it for you in 60 seconds. If you force the connection closed, then it should be instantly closed.

Marcus
  • 2,128
  • 20
  • 22
  • Are there guarantee that `BasicDataSource.getConnection()` return actual JDBC connection from driver and not a proxy or wrapper? Because that mean that `close()` may not have effect... – gavenkoa Jan 09 '15 at 21:51
  • 1
    It should close the connection directly. Here's another article with quite a bit of other info that you may find useful. http://stackoverflow.com/questions/7350680/dbcp-returns-closed-connections – Marcus Apr 09 '15 at 19:47