public abstract class PartitionedAllocator<T extends Recyclable> extends java.lang.Object implements Allocator<T>
Allocator implementation that allocates a single object per thread, similar to a ThreadLocal but more efficient. Objects created here are never released.| Modifier | Constructor and Description |
|---|---|
protected |
PartitionedAllocator(Supplier<T> factory) |
| Modifier and Type | Method and Description |
|---|---|
Reference<T> |
allocate()
Allocate an object from the internal pool.
|
java.util.List<Reference<T>> |
allocateBatch(int size)
Allocate a batch of objects all at once.
|
protected abstract long |
nextPartitionId() |
void |
release(java.util.List<Reference<T>> batch)
Efficiently release a batch of References all at once.
|
public Reference<T> allocate()
Allocatorallocate in interface Allocator<T extends Recyclable>Reference that can be retained and released.public java.util.List<Reference<T>> allocateBatch(int size)
AllocatorallocateBatch in interface Allocator<T extends Recyclable>size - the number of objects to allocateList of References to the allocated objectspublic void release(java.util.List<Reference<T>> batch)
Allocatorrelease in interface Allocator<T extends Recyclable>batch - the references to releaseprotected abstract long nextPartitionId()