4

I have a problem with BoneCP (0.7.1 RELEASE). I though that BoneCP.getConnection() ensures it would return Connection object assuming that DB is alive.

Here is how I configured my pool

private void setupConnectionPool() throws SQLException
{
    // setup the connection pool
    String connectUri = "jdbc:mysql://master-mysql:3306/base?zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&useCompression=true";

    BoneCPConfig config = new BoneCPConfig();
    config.setJdbcUrl(connectUri);
    config.setUsername("dbapp");
    config.setPassword("meh");
    config.setMinConnectionsPerPartition(5);
    config.setMaxConnectionsPerPartition(10);
    config.setPartitionCount(1);
    config.setConnectionTimeoutInMs(5 * 1000);

    this.connectionPool = new BoneCP(config); // setup the connection pool
}

then somewhere in the code I use it like this

    // I'm using Apache DbUtils
    QueryRunner run = new QueryRunner();
    Object result = run.query(this.connectionPool.getConnection(), query, handler, start, limit);

Attempt to run this query throws SQLException with state 08S01 (Communications link failure).

Subsequent call to this.connectionPool.getConnection() returns good connection.

But isn't it a whole point of connection pool so that I don't have to handle cases of lost connection myself?

expert
  • 29,290
  • 30
  • 110
  • 214

1 Answers1

4
  1. It should capture 08S01 and wipe out all the connections in the pool. However if you have multiple threads, you might have a thread that has already checked out a connection which might fail (the rest of the connections should become OK again).

  2. Please try out 0.8.0-beta3-SNAPSHOT; I have very recently cleaned up that implementation and added a bunch of robustness tests testing out various scenarios, amongst them, 08S01.

wwadge
  • 3,506
  • 1
  • 19
  • 28
  • Thank you! My sample app is single-threaded. Where can I download pre-compile jar ? There is only 0.7.1 on the website. – expert Nov 30 '12 at 22:35
  • 1
    Here: https://oss.sonatype.org/content/repositories/snapshots/com/jolbox/bonecp/0.8.0-beta3-SNAPSHOT/ – wwadge Nov 30 '12 at 22:53
  • 1
    (0.8.0-beta4, the non-snapshot version, is coming shortly in maven central) – wwadge Nov 30 '12 at 22:54