diff options
Diffstat (limited to 'yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java')
-rw-r--r-- | yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java b/yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java index fae01e8ac34..bdd059f3e17 100644 --- a/yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java +++ b/yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java @@ -18,7 +18,9 @@ public class ConcurrentResourcePool<T> implements Iterable<T> { private final Queue<T> pool = new ConcurrentLinkedQueue<>(); private final Supplier<T> factory; - // TODO: Deprecate + /** @deprecated Use {@link ConcurrentResourcePool(Supplier)} instead */ + @Deprecated(forRemoval = true, since = "7") + @SuppressWarnings("removal") public ConcurrentResourcePool(ResourceFactory<T> factory) { this.factory = factory.asSupplier(); } @@ -27,6 +29,12 @@ public class ConcurrentResourcePool<T> implements Iterable<T> { this.factory = factory; } + public void preallocate(int instances) { + for (int i = 0; i < instances; i++) { + pool.offer(factory.get()); + } + } + /** * Allocates an instance of the resource to the requestor. * The resource will be allocated exclusively to the requestor until it calls free(instance). |