Kanagavelu Sugumar
Kanagavelu Sugumar

Reputation: 19270

How DBConnectionPool will behave during Connection reset

In our project we are maintaining our own DB connection pool.
For resolving the issue 'java.sql.SQLRecoverableException: Io exception most of people has suggested to use standard connection pool like apache dbcp.

Kindly answer all my questions.

Upvotes: 1

Views: 1454

Answers (1)

shazin
shazin

Reputation: 21903

I am answering this question assuming that you made use of Apache DBCP for connection pooling by using org.apache.commons.pool.impl.GenericObjectPool, org.apache.commons.dbcp.DataSourceConnectionFactory, org.apache.commons.dbcp.PoolableConnectionFactory and org.apache.commons.dbcp.PoolingDataSource classes.

  • I am wondering what is the logic those standard pooling mechanism will perform during connection reset? If GenericObjectPool.testOnBorrow and GenericObjectPool.testOnReturn are set true to The Connection will be validated whether it is active or not using a validationQuery set in PoolableConnectionFactory. If the validation is failed the Connection object is dropped and new one is created and added to the pool
  • How do DBConnectionPool know that DB connection has timed out? since we know conn.isClosed() won't help here. Same mechanism as above
  • Is it each db connection will have one tcp client socket with DB server? Yes
  • Finally is it advisable; whenever i return the connection to the pool; pool should close the connection; if the connection is existing more than ~10 mins from it is created? [~10 mins server side conn timeout variable] If you think it should will not create unneccessary network traffic and if you have special reason to do that. You can do it. By setting minEvictableIdleTimeMillis in GenericObjectPool along with timeBetweenEvictionRunsMillis if you want to remove based on idle time

Upvotes: 2

Related Questions