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.
Entry
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| private int | |
| private final int[] | |
| pack-priv final Entry | |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| pack-priv | FixedInstancePool(int
the size of the fixed instance pool. size)Creates a new instance pool with the given size. |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized Entry | Returns: the next available entry in this instance poolRetrieves the next available entry in this instance pool. |
| protected abstract T | Returns: returns a new instance to use in the poolCreates 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 |
| count | back to summary |
|---|---|
| pack-priv int count | |
| head | back to summary |
|---|---|
| private int head | |
| instanceIndexes | back to summary |
|---|---|
| private final int[] instanceIndexes | |
| instancePool | back to summary |
|---|---|
| pack-priv final Entry<T>[] instancePool | |
| lastInstanceIndex | back to summary |
|---|---|
| private int lastInstanceIndex | |
| tail | back to summary |
|---|---|
| private int tail | |
| FixedInstancePool | back to summary |
|---|---|
| pack-priv FixedInstancePool(int size) Creates a new instance pool with the given size. Upon instantiation, the
| |
| allocate | back to summary |
|---|---|
| public synchronized Entry Retrieves the next available entry in this instance pool. Blocks until an entry becomes available (through
| |
| newInstance | back 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.
| |
| release | back to summary |
|---|---|
| public synchronized void release(Entry<T> e) Releases the given entry and makes it available for allocation (by
| |