Announcement Announcement Module
No announcement yet.
Reducing database connection acquisition timeout Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reducing database connection acquisition timeout


    I'm using Spring 2.5 + Hibernate 3.3. I've tried both with DBCP and now C3P0 and I can't seem to reduce the time it takes for the system to realise that the database connection is down.

    I mean, I turn off the database and I perform some DB operation and I have to wait like 1-2 minutes before an exception is thrown.

    Prior to this exception, like 30 seconds after I try to execute the DB operation, I get a log message:

    WARN |SQL Error: 0, SQLState: null
    ERROR|Connections could not be acquired from the underlying database!
    Thing is, it takes like 1 or 2 minutes *after* I see this message for the exceptions to be thrown. Can't this be reduced?! I've tried using

    <property name="loginTimeout" value="2" />
    for c3p0 but to no avail. I did read that for DBCP this wouldn't work. Seems it doesn't work either for c3p0 (or maybe there's some other setting).

    What can I do to reduce this timeout to say, 10 seconds? If a connection cannot be obtained from the underlying database within 10 seconds, I want to immediately receive an exception.

  • #2
    This combination seems to have done the trick. I now receive the exceptions fast enough.

        <property name="loginTimeout" value="2" />
        <property name="acquireRetryAttempts" value="1" />
        <property name="acquireRetryDelay" value="1000" />
    Is this the correct way to achieve what I'm looking for? I know it works, just want to make sure it's the right way