/** * Tests if this partition has hit a threshold and signal to the pool watch thread to create new connections * * @param connectionPartition to test for. */ protected void maybeSignalForMoreConnections(ConnectionPartition connectionPartition) { if (!connectionPartition.isUnableToCreateMoreTransactions() && !this.poolShuttingDown && connectionPartition.getAvailableConnections() * 100 / connectionPartition.getMaxConnections() <= this.poolAvailabilityThreshold) { connectionPartition.getPoolWatchThreadSignalQueue().offer(new Object()); // item being pushed is not important. } }
/** * Tests if this partition has hit a threshold and signal to the pool watch thread to create new connections * @param connectionPartition to test for. */ protected void maybeSignalForMoreConnections(ConnectionPartition connectionPartition) { if (!connectionPartition.isUnableToCreateMoreTransactions() && !this.poolShuttingDown && connectionPartition.getAvailableConnections()*100/connectionPartition.getMaxConnections() <= this.poolAvailabilityThreshold){ connectionPartition.getPoolWatchThreadSignalQueue().offer(new Object()); // item being pushed is not important. } }
@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; }