public PooledConnection(ConnectionManagerImpl manager, Connection connection) { // this.manager = manager; this.connection = connection; this.endpoint = connection.getEndpoint(); this.birthDate = System.nanoTime(); this.lastAccessed = this.birthDate; }
public synchronized boolean switchConnection(Connection newCon) throws InterruptedException { Connection oldCon = null; synchronized (this) { if (shouldDestroy()) return false; if (this.active && !shouldDestroy()) { this.waitingToSwitch = true; try { while (this.active && !shouldDestroy()) { wait(); } } finally { this.waitingToSwitch = false; notifyAll(); } } if (shouldDestroy()) return false; assert !this.active; final long now = System.nanoTime(); oldCon = this.connection; this.connection = newCon; this.endpoint = newCon.getEndpoint(); this.birthDate = now; } if (oldCon != null) { try { // do this outside of sync oldCon.close(false); } catch (Exception e) { // ignore } } return true; }