diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2022-04-26 18:11:53 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2022-04-26 18:30:57 +0200 |
commit | d180acf12edf1336044a940bd12d3ccb4758a588 (patch) | |
tree | fe0edc8154c50daea2fa553bec70216462325cbd /yolean | |
parent | 2d2a7d4a0bd306c7f9056fe80514af2e3a7d2661 (diff) |
Add preallocate() to ConcurrentResourcePool
Diffstat (limited to 'yolean')
-rw-r--r-- | yolean/abi-spec.json | 1 | ||||
-rw-r--r-- | yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java | 9 |
2 files changed, 9 insertions, 1 deletions
diff --git a/yolean/abi-spec.json b/yolean/abi-spec.json index 45ba75d736d..24ede8ce5cf 100644 --- a/yolean/abi-spec.json +++ b/yolean/abi-spec.json @@ -202,6 +202,7 @@ "methods": [ "public void <init>(com.yahoo.yolean.concurrent.ResourceFactory)", "public void <init>(java.util.function.Supplier)", + "public void preallocate(int)", "public final java.lang.Object alloc()", "public final void free(java.lang.Object)", "public java.util.Iterator iterator()" 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..4bcecb6fd73 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,8 @@ 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") public ConcurrentResourcePool(ResourceFactory<T> factory) { this.factory = factory.asSupplier(); } @@ -27,6 +28,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). |