BoneCP正确用法 [英] BoneCP correct usage
问题描述
我刚刚开始使用BoneCP并从作者网站中提取示例JDBC代码。
我有一个名为getConnection()的函数返回此处的连接是一个片段:
//设置连接池
BoneCPConfig config = new BoneCPConfig();
// Config到这里。
connectionPool = new BoneCP(config); //设置连接池
返回connectionPool.getConnection(); //获取连接
现在,我的问题:
1)我是否呼叫连接。 close()当我完成使用从上面的函数返回的连接,所以它返回到池或这是否完全关闭连接?如何返回到池的连接?
2)如何在应用程序退出时清理池?我结束时会调用connectionPool.shutdown()吗?而且,我读到某个地方我需要单独关闭所有池化连接?这是真的吗?
谢谢。
1 当你完成它时,总是调用 connection.close()
来返回到池的连接(它不会被物理关闭)。 / p>
2。当您完成所有操作后,请致电 connectionPool.shutDown()
游泳池并没有计划再次重新连接。
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 snippet:
// setup the connection pool
BoneCPConfig config = new BoneCPConfig();
// Config goes here.
connectionPool = new BoneCP(config); // setup the connection pool
return connectionPool.getConnection(); // fetch a connection
Now, my questions: 1) Do I call connection.close() when I am finished using the connection that is returned from above function so it is returned to the pool OR does this close the connection completely? How do I return connection to pool?
2) How to cleanup the pool on application quit? Do I call connectionPool.shutdown() when i'm finishing up? And also, I read somewhere that I need to close all pooled connections individually? Is this true?
Thanks.
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.
这篇关于BoneCP正确用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!