Search code examples
javaapache-commons-dbcp

What is maxWait in Apache DBCP?


I'm trying to understand what maxWait is in org.apache.commons.dbcp.BasicDataSource. Documentation said that it is:

The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.

But I still can't understand. I tried to google it, but my doubts only increased.

I see two ways to interpret this definition:

  1. maxWait is the maximum number of milliseconds that an application that uses this pool will wait until it gets an exception, if the pool does not have free connections to return to the application. I.e. if pool has no free connections application will wait for this amount of time for a new connection until it gets an exception.
  2. maxWait is the maximum number of milliseconds that connection can be opened. If such connection is not closed for this amount of time, pool will raise an exception.

Please help me to understand which statement is true. Or may be there is some other definition :)


Solution

  • maxWait should be the time your call to get a connection will wait in the pool prior to throwing an exception when all connections are currently busy.

    The behavior you describe in #2 appears to be the log abandoned timeout, which is how long a connection can be leased prior to the pool deciding it has been abandoned (not closed, which would just return it to the pool instead of actually closing it.)

    Check out http://commons.apache.org/proper/commons-dbcp/configuration.html to see the abandoned settings I am referring to.