#23 does idleconnintervalsecs support DBURL failover switch?


We have a requirement like after every idleconnintervalsecs test , if c3p0 does find bad/stale connection in the pool , it starts refurbishing connection from the same pool, but can c3p0 be configured in such a way to use some other DB url or failover URL, means automatic failover by c3p0 itself.

If c3p0 doesn't provide these feature , can these be implemented by any way , quick help/suggestion would be greatly appreciated.


  • keshav

    keshav - 2013-03-26
    • priority: 5 --> 9
  • Steve Waldman

    Steve Waldman - 2013-03-28
    • priority: 9 --> 5
  • Steve Waldman

    Steve Waldman - 2013-03-28


    c3p0 doesn't yet implement hooks for failovers, although a lot of the pieces are there. in particular, you can call setJdbcUrl / setUser / setPassword on a ComboPooledDataSource at any time, and c3p0 will handle the change gracefully. the trick is figuring out what constitutes a condition that should trigger the failover.

    i've considered trying to add support for monitoring this. one approach, already available, would be to write a ConnectionTester that made the decision based on Exceptions that occur. Unfortunately, Connection test Exceptions alone may not be sufficient to distinguish between transient problems (e.g. a Connection has timed out) and problems that indicate the database is dead. c3p0 does already try to sense Exceptions that signal an invalid database, using the SQLSTATE of SQLExceptions, but this is unreliable as SQLSTATE values are inconsistently and unreliably supported by databases and JDBC driver vendors. An alternative approach that would be easy to add would be to let a full round of Connection acquisition failures provoke an event, that users could respond to by resetting Connection info. I will think about adding this. If you wanted to do it yourself, you'd want to look at BasicResourcePool.java, and wherever the method forceKillAcquires is called (two places), you'd also want to signal that a failover might be appropriate. You've got to be very careful about threading and locks in this code -- it is the heart and hard part of c3p0. I'll try to implement some means of handling this, but that's where you'd play if you are impatient.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks