Domanda

I was reading up on tuning JDBC connection pool configurations and under the Timeout Settings >> Idle Timeout section, it reads:

For best performance, set Idle Timeout to zero (0) seconds, so that idle connections will not be removed. This ensures that there is normally no penalty in creating new connections and disables the idle monitor thread. However, there is a risk that the database server will reset a connection that is unused for too long.

This last sentence is disconcerting. On Tomcat, you can specify a JDBC connection as a JNDI lookup from inside context.xml. I assume that the Idle Timeout field in the link above correspond's to Tomcat's (DBCP's) maxIdle property.

So I ask: what happens if I set maxIdle to 0, which tells DBCP not to remove idle connections, but then the server hangs up on (or resets) the idle connection? Is there a specific exception that gets called? Will the app just hang? How can I mitigate such problems but still keep maxIdle at 0?

È stato utile?

Soluzione

With the Tomcat or DBCP connection pool, you would mitigate such problems by using validation queries, to have the health of the connection checked when the connection is checked out from the pool (this is the validateOnBorrow property).

With the Tomcat pool, you can instead configure it to validate the idle connections periodically (validateWhileIdle, I believe) rather than having the connection checked on every single use of it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top