5

I have a DBCP connection pool in Tomcat. The problem is that when the connection is lost briefly the appliction is broken because DBCP won't try to reconnect again later when there is a connection. Can I get DBCP to reconnect automatically?

skaffman
  • 398,947
  • 96
  • 818
  • 769
wesley
  • 51
  • 1
  • 1
  • 2
  • To be sure, do you call `connection.close()` in the `finally` block of the `try` block as you acquired it? Everywhere? *Really?* Yes? – BalusC Mar 30 '10 at 20:37

2 Answers2

5

There are 2 ways to "solve" this, though both have some issues:

  1. You can use a "validationQuery" (see below) to have a test query run before you go (generally something like 'select 1 from dual' which will be used to test connections before/after you get/give them to the pool. This adds an extra call per connection request from the pool. See: http://wiki.apache.org/commons/DBCP

  2. Instead of doing this per query, you can have the idleEvictorThread do it by setting testWhileIdle, though in some versions that thread can cause deadlocking under high-load. See: http://commons.apache.org/dbcp/configuration.html for more details on that and other options

jayshao
  • 2,167
  • 2
  • 15
  • 17
1

Don't think DBCP does that, but BoneCP (http://jolbox.com) can be configured to automatically replay any transactions when the DB or network goes down. It's completely transparent to your application.

wwadge
  • 3,506
  • 1
  • 19
  • 28
  • 1
    Check out the transactionReplay feature. Don't use this with Hibernate though (they have bugs) – wwadge Sep 12 '11 at 15:35