SharingObjectPool implements RecyclingSupplier<T> { @Override public void recycle(final T object, final Exception e) { if (e != null) { if (asyncValidate) { DefaultExecutor.INSTANCE.execute(new AbstractRunnable(true) { @Override public void doRun() { validate(object, e); } }); } else { validate(object, e); } } else { returnToQueue(object); } } SharingObjectPool(final Factory<T> factory, final int coreSize, final int maxSize);  SharingObjectPool(final Factory<T> factory, final int coreSize, final int maxSize,
          final boolean asyncValidate); @Override @Nullable synchronized T tryGet(final long deadlineNanos); @Override void recycle(final T object, final Exception e); @Override void recycle(final T object); @Override synchronized boolean tryDispose(final long timeoutMillis); @Override synchronized String toString();  }
@Test @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") public void testSharingPool() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException { SharingObjectPool<String> pool = createTestPool(); String obj = pool.get(); Assert.assertEquals("O0", obj); String obj2 = pool.get(); Assert.assertEquals("O1", obj2); pool.recycle(obj); String obj3 = pool.get(); Assert.assertEquals("O0", obj3); }
@Test @SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS") public void testSharingPool2() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException { SharingObjectPool<String> pool = createTestPool(); String obj = pool.get(); Assert.assertEquals("O0", obj); pool.recycle(obj); String obj2 = pool.get(); Assert.assertEquals("O0", obj2); }