Top Description Fields Constructors Methods
com.univocity.parsers.common.input.concurrent

pack-priv abstract Class FixedInstancePool<T>

extends Object
Class Inheritance
Type Parameters
<T>
the class of objects stored in the instance pool
Imports
java.util.*

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 FixedInstancePool#allocate() to get an available Entry from the pool. If all objects are allocated then the thread will block until an element is released.

FixedInstancePool#release(Entry) releases an allocated Entry for reuse.

Author
Univocity Software Pty Ltd - [email protected]
See Also
Entry

Field Summary

Modifier and TypeField and Description
pack-priv int
private int
private final int[]
pack-priv final Entry<T>[]
private int
private int

Constructor Summary

AccessConstructor and Description
pack-priv
FixedInstancePool(int
the size of the fixed instance pool.
size
)

Creates a new instance pool with the given size.

Method Summary

Modifier and TypeMethod and Description
public synchronized Entry<T>

Returns:

the next available entry in this instance pool
allocate
()

Retrieves the next available entry in this instance pool.

protected abstract T

Returns:

returns a new instance to use in the pool
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.

public synchronized void
release(Entry<T>
the entry to be released and made available for reuse.
e
)

Releases the given entry and makes it available for allocation (by FixedInstancePool#allocate())

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
pack-priv int count
instanceIndexesback to summary
private final int[] instanceIndexes
instancePoolback to summary
pack-priv final Entry<T>[] instancePool
lastInstanceIndexback to summary
private int lastInstanceIndex
tailback to summary
private int tail

Constructor Detail

FixedInstancePoolback to summary
pack-priv FixedInstancePool(int size)

Creates a new instance pool with the given size. Upon instantiation, the FixedInstancePool#newInstance() 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:int

the size of the fixed instance pool.

Annotations
@SuppressWarnings:unchecked

Method Detail

allocateback to summary
public synchronized Entry<T> allocate()

Retrieves the next available entry in this instance pool. Blocks until an entry becomes available (through FixedInstancePool#release(Entry)).

Returns:Entry<T>

the next available entry in this instance pool

newInstanceback to summary
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:T

returns a new instance to use in the pool

releaseback to summary
public synchronized void release(Entry<T> e)

Releases the given entry and makes it available for allocation (by FixedInstancePool#allocate())

Parameters
e:Entry<T>

the entry to be released and made available for reuse.