Pergunta

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?

Foi útil?

Solução

  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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top