Class FixedInstancePool<T>
java.lang.Object
com.univocity.parsers.common.input.concurrent.FixedInstancePool<T>
- Type Parameters:
T
- the class of objects stored in the instance pool
A very simple object instance pool with a fixed size.
This is essentially an immutable circular queue. Elements are not added nor removed. Pointers to the head and tail of the queue identify what is the next available entry.
Use allocate()
to get an available Entry
from the pool. If all objects are allocated then the thread will block until an element is released.
release(Entry)
releases an allocated Entry
for reuse.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int
private int
private final int[]
private int
private int
-
Constructor Summary
ConstructorsConstructorDescriptionFixedInstancePool
(int size) Creates a new instance pool with the given size. -
Method Summary
Modifier and TypeMethodDescriptionallocate()
Retrieves the next available entry in this instance pool.protected abstract T
Creates a new instance of the given type of objects stored as entries of this instance pool This method is called in the constructor of this class for initialization of the instance array and must always return a new instance.void
Releases the given entry and makes it available for allocation (byallocate()
)
-
Field Details
-
instancePool
-
instanceIndexes
private final int[] instanceIndexes -
head
private int head -
tail
private int tail -
count
int count -
lastInstanceIndex
private int lastInstanceIndex
-
-
Constructor Details
-
FixedInstancePool
FixedInstancePool(int size) Creates a new instance pool with the given size. Upon instantiation, thenewInstance()
method will be called to fill in the instance pool, and the pool can then have its entries allocated for use (and reuse).- Parameters:
size
- the size of the fixed instance pool.
-
-
Method Details
-
newInstance
Creates a new instance of the given type of objects stored as entries of this instance pool This method is called in the constructor of this class for initialization of the instance array and must always return a new instance.- Returns:
- returns a new instance to use in the pool
-
allocate
Retrieves the next available entry in this instance pool. Blocks until an entry becomes available (throughrelease(Entry)
).- Returns:
- the next available entry in this instance pool
-
release
Releases the given entry and makes it available for allocation (byallocate()
)- Parameters:
e
- the entry to be released and made available for reuse.
-