I just started using BoneCP, and this is my first time using the connection pool. I am a bit confused about how I should use this. I am currently saving a BoneCP object as a static variable, and therefore I can use it between different connections.
When I finished the connection, I will close it connection.close() .
Should I do this, or should I not close it so that it can be reused by the pool?
This is my current implementation to get the connection:
private static BoneCP connectionPool; public Connection getConnection() throws SQLException { if (connectionPool == null) { initPool(); } return connectionPool.getConnection(); } private void initPool() throws SQLException { BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl(DB_URL); config.setUsername(DB_USERNAME); config.setPassword(DB_PASSWORD); config.setMinConnectionsPerPartition(5); config.setMaxConnectionsPerPartition(10); config.setPartitionCount(1); connectionPool = new BoneCP(config); }
Does this seem correct or did I misunderstand how should I use BoneCP?
pgsandstrom
source share