Auto-connect database connection

I have a DBCP connection pool in Tomcat. The problem is that when the connection is shorted, the application is interrupted because DBCP will not try to reconnect later when there is a connection. Can I get DBCP to automatically connect?

+4
source share
2 answers

There are two ways to "solve" this, although both have some problems:

  • You can use "validationQuery" (see below) to run a test query before you go (usually something like "select 1 from dual", which will be used to check connections before / after you receive / give back they are added by an additional call to request a connection from the pool. See http://wiki.apache.org/commons/DBCP

  • Instead, for each request, you can use idleEvictorThread by setting testWhileIdle, although in some versions this thread may cause blocking under heavy load. See http://commons.apache.org/dbcp/configuration.html for more information about this and other options.

+4
source

Do not think DBCP does this, but BoneCP ( http://jolbox.com ) can be configured to automatically play back any transactions when the database or network goes down. It is completely transparent to your application.

+1
source

Source: https://habr.com/ru/post/1305599/


All Articles