/** * 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); } }
/** * 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); } }