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
abstract class FixedInstancePool<T> extends java.lang.Object
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 availableEntry
from the pool. If all objects are allocated then the thread will block until an element is released.release(Entry)
releases an allocatedEntry
for reuse.- See Also:
Entry
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
count
private int
head
private int[]
instanceIndexes
(package private) Entry<T>[]
instancePool
private int
lastInstanceIndex
private int
tail
-
Constructor Summary
Constructors Constructor Description FixedInstancePool(int size)
Creates a new instance pool with the given size.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Entry<T>
allocate()
Retrieves the next available entry in this instance pool.protected abstract T
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.void
release(Entry<T> e)
Releases the given entry and makes it available for allocation (byallocate()
)
-
-
-
Constructor Detail
-
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 Detail
-
newInstance
protected abstract T 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
public Entry<T> 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
public void release(Entry<T> e)
Releases the given entry and makes it available for allocation (byallocate()
)- Parameters:
e
- the entry to be released and made available for reuse.
-
-