Search code examples
javadatabaseconnection-poolingbonecp

How to log connection pool data using BoneCP


Does anyone know hot to log connection pool data (i.e. number of open and idle db connections) using BoneCP? It's easy to achieve using C3P0 which I'm migrating from (in fact this information is logged by default there) but it seems to be harder to get sing BoneCP. For now what I see in logs is raw SQL statements.


Solution

  • Use the Statistics class. For example: ...set up BoneCP connectionPool object

    Statistics stats = connectionPool.getStatistics() (previously getStats but later renamed)
    return
    "Tot Conn Created:   " + stats.getTotalCreatedConnections() +
    "Tot Free Conn:      " + stats.getTotalFree() +
    "Tot Leased Conn:    " + stats.getTotalLeased();