BoneCP correct usage

后端 未结 2 852
走了就别回头了
走了就别回头了 2021-01-02 07:09

I\'ve just started using BoneCP and pulled the sample JDBC code from the authors site.

I have a function called getConnection() that returns a connection here is a s

相关标签:
2条回答
  • 2021-01-02 07:41
     Connection connection = dbPool.getConnection();
    

    The Connection object gotten from the pool, is a wrapper class. It will maintain the underlying connection properly even in the Exception.

    Even in the Connection related exceptions, for example, TERMINATE_ALL_CONNECTIONS, the BoneCP pool will properly close all the underlying connections.

    In summary, BoneCP pool make the cache transparent. Client side only need follow the stand flow,

    1. request the connection (take the connection from pool, pool will decide whether to re-use/create one)
    2. request the PreparedStatement/CallableStatement (reuse the object from pool if it is enabled)
    3. execute the statements
    4. close statement, (release the statement object to the pool if it is enabled)
    5. close connection, (release the connection object to the pool)

    When application stop, shutdown the pool to release all the cached connections.

    boneCP.shutdown()
    
    0 讨论(0)
  • 2021-01-02 07:54

    1. Always call connection.close() to return the connection to the pool (it won't be physically closed) when you're done with it.

    2. Call connectionPool.shutDown() when you're completely done with the pool and not planning of reconnecting again.

    0 讨论(0)
提交回复
热议问题