/** * Release the lock on the given iterator, returning it to the pool. * * @param iterator Iterator to return to the pool. */ public void release(I iterator) { synchronized (this) { // Find and remove the resource from the list of allocated resources. T resource = resourceAssignments.get(iterator); Object obj = resourceAssignments.remove(iterator); // Close the iterator. iterator.close(); // make sure we actually removed the assignment if (obj == null) throw new ReviewedStingException( "Failed to remove resource assignment; target key had no associated value in the resource assignment map"); // Return the resource to the pool. if (!allResources.contains(resource)) throw new ReviewedStingException("Iterator does not belong to the given pool."); availableResources.add(resource); } }