Package org.jgroups.util
Class Pool<T>
- java.lang.Object
-
- org.jgroups.util.Pool<T>
-
public class Pool<T> extends java.lang.Object
Manages a fixed pool of resources (e.g. buffers). Uses the fast try-lock operation to get a resource from the pool, or returns a newly created resource. When the returned lock is unlocked, that resource becomes available again for consumption- Since:
- 3.5
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Pool.Element<T>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pool.Element<T>
get()
Gets the next available resource for which the lock can be acquired and returns it and its associated lock, which needs to be released when the caller is done using the resource.T[]
getElements()
int
getNumLocked()
static void
main(java.lang.String[] args)
java.lang.String
toString()
-
-
-
Constructor Detail
-
Pool
public Pool(int capacity, java.util.function.Supplier<T> creator)
-
-
Method Detail
-
getElements
public T[] getElements()
-
getNumLocked
public int getNumLocked()
-
get
public Pool.Element<T> get()
Gets the next available resource for which the lock can be acquired and returns it and its associated lock, which needs to be released when the caller is done using the resource. If no resource in the pool can be locked, returns a newly created resource and a null lock. This means that no lock was acquired and thus doesn't need to be released.- Returns:
- An Element with T and a lock (possibly null if newly created)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
-