[...] Note, however, that Connection pools work best when you obtain a Connection, do everything you can with it quickly, then close the Connection. You should not attempt to hold the same Connection for long periods of time. [...]
+1 from here
usual case is that jdbc connection pool timeout is set to value higher at backend database timeout,
let's say you're using mysql database, with timeout 120 seconds for idle connection, and jdbc is
configured for 180 seconds. In this case it's just meaner of time when you will get problems, because
your jdbc connection pool trying to re-use your connection which is actually closed at the other side already.
you can also configure validationQuery, which will be executed against your database to verify if connection
is still active and in good state, before jdbc connection pool will return that connection to your tomcat apps.
That's the basic JNDI common attribute.
You can do further and use some of tomcat specific JDBC "enhanced attributes" (as long as long you don't
plan to move your app to other servlet container or something bigger like jboss). With tomcat enhanced
attributes you may try to use "validationInterval" which will (kind of) force to do connection validation
every XX seconds instead of every time you're trying to use it. And if you're trying to re-use connection
that was validated already 30 seconds ago, it will not validate it again and assume it is active.