private T doGetItem() { T item = this.available.poll(); if (item != null && this.logger.isDebugEnabled()) { this.logger.debug("Obtained " + item + " from pool."); } if (item == null) { item = this.callback.createForPool(); if (this.logger.isDebugEnabled()) { this.logger.debug("Obtained new " + item + "."); } this.allocated.add(item); } else if (this.callback.isStale(item)) { if (this.logger.isDebugEnabled()) { this.logger.debug("Received a stale item " + item + ", will attempt to get a new one."); } doRemoveItem(item); item = doGetItem(); } this.inUse.add(item); return item; }
/** * Obtains an item from the pool; waits up to waitTime milliseconds (default infinity). * @throws PoolItemNotAvailableException if no items become available in time. */ @Override public T getItem() { boolean permitted = false; try { try { permitted = this.permits.tryAcquire(this.waitTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PoolItemNotAvailableException("Interrupted awaiting a pooled resource", e); } if (!permitted) { throw new PoolItemNotAvailableException("Timed out while waiting to acquire a pool entry."); } return doGetItem(); } catch (Exception e) { if (permitted) { this.permits.release(); } if (e instanceof PoolItemNotAvailableException) { throw (PoolItemNotAvailableException) e; } throw new PoolItemNotAvailableException("Failed to obtain pooled item", e); } }
private T doGetItem() { T item = this.available.poll(); if (item != null && this.logger.isDebugEnabled()) { this.logger.debug("Obtained " + item + " from pool."); } if (item == null) { item = this.callback.createForPool(); if (this.logger.isDebugEnabled()) { this.logger.debug("Obtained new " + item + "."); } this.allocated.add(item); } else if (this.callback.isStale(item)) { if (this.logger.isDebugEnabled()) { this.logger.debug("Received a stale item " + item + ", will attempt to get a new one."); } doRemoveItem(item); item = doGetItem(); } this.inUse.add(item); return item; }
/** * Obtains an item from the pool; waits up to waitTime milliseconds (default infinity). * @throws PoolItemNotAvailableException if no items become available in time. */ @Override public T getItem() { boolean permitted = false; try { try { permitted = this.permits.tryAcquire(this.waitTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new PoolItemNotAvailableException("Interrupted awaiting a pooled resource", e); } if (!permitted) { throw new PoolItemNotAvailableException("Timed out while waiting to acquire a pool entry."); } return doGetItem(); } catch (Exception e) { if (permitted) { this.permits.release(); } if (e instanceof PoolItemNotAvailableException) { throw (PoolItemNotAvailableException) e; } throw new PoolItemNotAvailableException("Failed to obtain pooled item", e); } }