lundi 4 mai 2015

Reuse or not to reuse connections off a connection pool

Lets say I am "reusing" connections like below in a multithreaded environment (details of exception handling and closing of resources are ommitted for the sake of brevity):

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
}

Does the above approach perform better(and scalable) than to have each of the above methods to get(/open) the connections, do their works and close the connections(and other associated resources, of course) by themselves?

Aucun commentaire:

Enregistrer un commentaire