SimpleSmartObjectPool implements SmartRecyclingSupplier<T> { @Override public void recycle(final T object, final ObjectBorower borower) { lock.lock(); try { if (!borrowedObjects.remove(borower, object)) { Entry<ObjectBorower<T>, T> foundEntry = null; for (Entry<ObjectBorower<T>, T> entry : borrowedObjects.entries()) { final ObjectBorower<T> lb = entry.getKey(); if (lb == borower) { continue; } if (lb.nevermind(entry.getValue())) { foundEntry = entry; break; } } if (foundEntry == null) { throw new IllegalStateException("Object " + object + " has not been borrowed from this pool"); } else { if (!borrowedObjects.remove(foundEntry.getKey(), foundEntry.getValue())) { throw new IllegalStateException("Should have removed " + foundEntry); } } } availableObjects.add(object); available.signalAll(); } finally { lock.unlock(); } } SimpleSmartObjectPool(final int initialSize, final int maxSize,
          final RecyclingSupplier.Factory<T> factory, final boolean fair); @Override @SuppressFBWarnings({"RV_RETURN_VALUE_IGNORED_BAD_PRACTICE", "PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS"}) @Nullable T tryGet(final ObjectBorower borower, final long deadlineNanos); @Override void recycle(final T object, final ObjectBorower borower); @Override boolean tryDispose(final long timeoutMillis); @SuppressFBWarnings("EXS_EXCEPTION_SOFTENING_HAS_CHECKED") @Override boolean scan(final ScanHandler<T> handler); @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") void requestReturnFromBorrowersIfNotInUse(); @Override String toString(); @Override T getSample();  }
@Test public void testPool() throws InterruptedException, TimeoutException, ObjectCreationException, ObjectDisposeException { borowedObject = instance.get(this); Assert.assertNotNull(borowedObject); instance.recycle(borowedObject, this); instance.dispose(); }