@Override public void cleanupConnection(ConnectionHandle oldHandle, ConnectionHandle newHandle) { this.threadFinalizableRefs.remove(oldHandle); this.threadWatch(newHandle); }
this.cachedPoolStrategy = config.getPoolStrategy() != null && config.getPoolStrategy().equalsIgnoreCase("CACHED"); if (this.cachedPoolStrategy) { this.connectionStrategy = new CachedConnectionStrategy(this, new DefaultConnectionStrategy(this)); } else { this.connectionStrategy = new DefaultConnectionStrategy(this);
@Override protected Connection getConnectionInternal() throws SQLException { // try to get the connection from thread local storage. SimpleEntry<ConnectionHandle, Boolean> result = this.tlConnections.get(); // we should always be successful. If not, it means we have more threads asking // us for a connection than we've got available. This is not supported so we flip // back our strategy. if (result == null){ this.pool.cachedPoolStrategy = false; this.pool.connectionStrategy = this.fallbackStrategy; stealExistingAllocations(); // get a connection as if under our fallback strategy now. return (ConnectionHandle) this.pool.connectionStrategy.getConnection(); } return result.getKey(); }
this.cachedPoolStrategy = config.getPoolStrategy() != null && config.getPoolStrategy().equalsIgnoreCase("CACHED"); if (this.cachedPoolStrategy){ this.connectionStrategy = new CachedConnectionStrategy(this, new DefaultConnectionStrategy(this)); } else { this.connectionStrategy = new DefaultConnectionStrategy(this);
@Override protected SimpleEntry<ConnectionHandle, Boolean> initialValue() { SimpleEntry<ConnectionHandle, Boolean> result = null; ConnectionHandle c = null; // grab a connection from any other configured fallback strategy for (int i=0; i < 4*3; i++){ // there is a slight race with the pool watch creation thread so spin for a bit // no big deal if it keeps failing, we just switch to default connection strategy c = (ConnectionHandle)this.fallbackStrategy.pollConnection(); if (c != null){ break; } // oh-huh? either we are racing while resizing the pool or else no of threads > no of connections. Let's wait a bit // and try again one last time Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } if (c != null){ result = new SimpleEntry<ConnectionHandle, Boolean>(c, false); this.ccs.threadWatch(c); } return result; }