views:

954

answers:

3

I'm using proxool java connection pool (version 0.9.1). Everything works fine till I reach the maximum connection count. If the maximum connection count is reached proxool immediately throws an SQLExcepion:

java.sql.SQLException: Couldn't get connection because we are at maximum 
connection count (n/n) and there are none available

Of course instead of n the maximum connection count is shown.

Why is proxool throwing an SQLException immediately instead of waiting for an available connection? Not forever of course, but a configurable timeout would be great.

I don't know if it important, but I'm using proxool in a Tomcat J2EE application. Parameters of proxool are defined in context.xml and I'm using Proxool DataSource Support.

+1  A: 

I took a quick look at the source code and this looks like the standard behavior for ConnectionPool.getConnection. The documentation says the same thing.

There are other database pooling libraries (such as Apache DBCP and C3P0) but you'd have to do some refactoring to use them. The alternative is to wrap the getConnection method yourself (or modify the proxool source) and make it work the way you want.

jdigital
+1  A: 

I was asking the question on the proxool mailing list and I got a quick, yet unfortunately negative answer.

Now there is no support for configurable (or any kind of) timeout, however there are plans to implement this feature.

rics
A: 

You can use Thread.sleep() to handle it. Proxool throws an exception when the maximum connection number is reached. Once you detect it, you can wait for a little while by calling "Thread.sleep()", hopefully after this amount of time, the connections will be available again.

public Connection getConnection() throws SQLException {
    Connection conn = null;
    while (conn ==null){
      try {
        conn = DriverManager.getConnection("proxool."+connectionPoolAlias);
      } catch (SQLException e) {
        e.printStackTrace();
        String methodName =e.getStackTrace()[0].getMethodName();
        if (methodName.equalsIgnoreCase("checkSimultaneousBuildThrottle") || 
                                     methodName.equalsIgnoreCase("quickRefuse")){
          try{
            Thread.sleep(500);
          }catch( InterruptedException ie){}
        }else{
          throw e;
        }
      }
    }
    return conn;
  }
Winston Chen