@Override public ConnectionHandle pollConnection(){ ConnectionHandle result = null; int partition = (int) (Thread.currentThread().getId() % this.pool.partitionCount); ConnectionPartition connectionPartition = this.pool.partitions[partition]; result = connectionPartition.getFreeConnections().poll(); if (result == null) { // we ran out of space on this partition, pick another free one for (int i=0; i < this.pool.partitionCount; i++){ if (i == partition) { continue; // we already determined it's not here } result = this.pool.partitions[i].getFreeConnections().poll(); // try our luck with this partition if (result != null) { connectionPartition = this.pool.partitions[i]; // we found it here break; // we found a connection } } } if (!connectionPartition.isUnableToCreateMoreTransactions()){ // unless we can't create any more connections... this.pool.maybeSignalForMoreConnections(connectionPartition); // see if we need to create more } return result; }
postDestroyConnection(connectionHandle); maybeSignalForMoreConnections(connectionPartition); connectionHandle.clearStatementCaches(true); return; // don't place back in queue - connection is broken or expired.
postDestroyConnection(connectionHandle); maybeSignalForMoreConnections(connectionPartition); connectionHandle.clearStatementCaches(true); return; // don't place back in queue - connection is broken or expired.