public abstract class Allocator extends Object
This class represents an object allocator; instances of this class
are generated by AllocatorContext.
If an allocator has recycled objects available, those are returned first, before allocating new ones.
Allocator instances are thread-safe without synchronization,
they are the "production lines" of the factories,
their implementation is derived from the AllocatorContext
to which they belong (e.g. heap allocators for HeapContext).
AllocatorContext.getAllocator(ObjectFactory)| Modifier and Type | Field and Description |
|---|---|
protected Object[] |
queue
Holds the queue of objects belonging to this allocator
(always used first when available).
|
protected int |
queueSize
Holds the number of objects in this allocator queue.
|
protected Thread |
user
Holds the current user or
null if deactivated. |
| Modifier | Constructor and Description |
|---|---|
protected |
Allocator()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract Object |
allocate()
Allocates a new object, this method is called when the allocator queue
is empty.
|
Object |
next()
Returns the next available object from this allocator queue or
allocate() one if none available. |
protected abstract void |
recycle(Object object)
Recycles the specified object to this queue.
|
protected Thread user
null if deactivated.protected Object[] queue
protected int queueSize
public final Object next()
allocate() one if none available.protected abstract Object allocate()
protected abstract void recycle(Object object)
object - the object to recycle.Copyright © 2005–2021 Javolution. All rights reserved.