0
可以說,我是「重用」,在多線程環境中像下面連接(異常處理和資源的閉合細節ommitted爲簡潔起見):重用或不重用掀起了連接池的連接
public contractMethod(){
Connection conn = getConnectionFromJndiDSBackedByAPool();
methodA(conn);
// close conn
}
private methodA(Connection conn) {
// do lots of things with the conn
// close statements & resultsets
methodB(conn);
}
private methodB(Connection conn) {
// do lots of things with the conn
// close statements & resultsets
}
上述方法是否比上述方法獲得(/打開)連接,完成它們的工作並自己關閉連接(當然還有其他相關資源)更好(和可擴展)?