連接池重用連接。 以下是apache dbcp如何工作的下劃線。
Connection poolableConnection= apacheDbcpDataSource.getConnection();
阿帕奇DBCP實現返回連接包裝是類型PoolableConnection的。
poolableConnection.close();
PoolableConnection.close()檢查,如果實際的底層連接被關閉或沒有,如果不是則返回這個PoolableConnection實例放入連接池(在這種情況下GenericObjectPool)。
if (!isUnderlyingConectionClosed) {
// Normal close: underlying connection is still open, so we
// simply need to return this proxy to the pool
try {
genericObjectPool.returnObject(this); //this is PoolableConnection instance in this case
....
}
只是好奇,但哪個連接池庫啓動單獨的線程管理池?我不認爲commons-dbcp這樣做 - 至少不是BasicDataSource。相反,我認爲連接檢查是在連接從池中檢出時完成的 – 2010-06-21 11:57:04