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.