summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-04-26 19:38:45 +0200
committerGitHub <noreply@github.com>2022-04-26 19:38:45 +0200
commit4065b27e668814a6ff5f240204cf0ae10123e783 (patch)
tree8bf670c162827c4fc707e6e9f111ddef152ca415
parente9555d0bf274a26adc4021601bd318760074c91e (diff)
parentd180acf12edf1336044a940bd12d3ccb4758a588 (diff)
Merge pull request #22290 from vespa-engine/bjorncs/dhr-fix
Add preallocate() to ConcurrentResourcePool
-rw-r--r--yolean/abi-spec.json1
-rw-r--r--yolean/src/main/java/com/yahoo/yolean/concurrent/ConcurrentResourcePool.java9
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).