Class Recycler<T>
java.lang.Object
io.netty.util.Recycler<T>
- Type Parameters:
T- the type of the pooled object
- Direct Known Subclasses:
AdaptivePoolingAllocator.Magazine.AdaptiveRecycler
Light-weight object pool based on a thread-local stack.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThis is an implementation ofMessagePassingQueue, similar to what might be returned fromPlatformDependent.newMpscQueue(int), but intended to be used for debugging purpose.private static final classstatic classprivate static final classstatic interfaceprivate static classprivate static final classWe created this handle to avoid having more than 2 concrete implementations ofRecycler.EnhancedHandlei.e.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate static final booleanprivate static final intprivate static final intprivate static final intprivate final Recycler.LocalPool<?, T> private static final InternalLoggerprivate static final Recycler.EnhancedHandle<?> private static final Recycler.UnguardedLocalPool<?> private static final intprivate final FastThreadLocal<Recycler.LocalPool<?, T>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRecycler()protectedRecycler(boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = true: it means thatObjectPool.Handle.recycle(Object)is not checking thatobjectis the same which was recycled and assume no other recycling happens concurrently (similar to whatRecycler.EnhancedHandle.unguardedRecycle(Object)does).protectedRecycler(int maxCapacityPerThread) protectedRecycler(int maxCapacity, boolean unguarded) USE IT CAREFULLY!
This is creating a shareableRecyclerwhichget()can be called concurrently from differentThreads.
UsuallyRecyclers uses some form of thread-local storage, but this constructor is disabling it and using a single pool of instances instead, sized asmaxCapacity
This is NOT enforcing pooled instances states to be validated ifunguarded = true: it means thatObjectPool.Handle.recycle(Object)is not checking thatobjectis the same which was recycled and assume no other recycling happens concurrently (similar to whatRecycler.EnhancedHandle.unguardedRecycle(Object)does).protectedRecycler(int maxCapacityPerThread, int maxSharedCapacityFactor) Deprecated.protectedRecycler(int chunksSize, int maxCapacityPerThread, boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = trueas stated byRecycler(boolean), but it allows to tune the chunk size used for local pooling.protectedRecycler(int maxCapacityPerThread, int interval, int chunkSize) protectedRecycler(int maxCapacityPerThread, int interval, int chunkSize, boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded =trueas stated byRecycler(boolean).privateRecycler(int maxCapacityPerThread, int ratio, int chunkSize, boolean useThreadLocalStorage, Thread owner, boolean unguarded) protectedRecycler(int maxCapacityPerThread, int maxSharedCapacityFactor, int ratio, int maxDelayedQueuesPerThread) Deprecated.protectedRecycler(int maxCapacityPerThread, int maxSharedCapacityFactor, int ratio, int maxDelayedQueuesPerThread, int delayedQueueRatio) Deprecated.protectedUSE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded =trueas stated byRecycler(boolean).protectedUSE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = trueand allows pinning the recycler to a specificThread, as stated byRecycler(Thread, boolean).
It also allows tuning the chunk size used for local pooling and the max capacity per thread.protectedUSE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = trueas stated byRecycler(boolean)and allows to pin the recycler to a specificThread, ifowneris notnull. -
Method Summary
Modifier and TypeMethodDescriptionfinal Tget()protected abstract TnewObject(Recycler.Handle<T> handle) final booleanrecycle(T o, Recycler.Handle<T> handle) Deprecated.(package private) final intstatic voidunpinOwner(Recycler<?> recycler)
-
Field Details
-
logger
-
NOOP_HANDLE
-
NOOP_LOCAL_POOL
-
DEFAULT_INITIAL_MAX_CAPACITY_PER_THREAD
private static final int DEFAULT_INITIAL_MAX_CAPACITY_PER_THREAD- See Also:
-
DEFAULT_MAX_CAPACITY_PER_THREAD
private static final int DEFAULT_MAX_CAPACITY_PER_THREAD -
RATIO
private static final int RATIO -
DEFAULT_QUEUE_CHUNK_SIZE_PER_THREAD
private static final int DEFAULT_QUEUE_CHUNK_SIZE_PER_THREAD -
BLOCKING_POOL
private static final boolean BLOCKING_POOL -
BATCH_FAST_TL_ONLY
private static final boolean BATCH_FAST_TL_ONLY -
localPool
-
threadLocalPool
-
-
Constructor Details
-
Recycler
protected Recycler(int maxCapacity, boolean unguarded) USE IT CAREFULLY!
This is creating a shareableRecyclerwhichget()can be called concurrently from differentThreads.
UsuallyRecyclers uses some form of thread-local storage, but this constructor is disabling it and using a single pool of instances instead, sized asmaxCapacity
This is NOT enforcing pooled instances states to be validated ifunguarded = true: it means thatObjectPool.Handle.recycle(Object)is not checking thatobjectis the same which was recycled and assume no other recycling happens concurrently (similar to whatRecycler.EnhancedHandle.unguardedRecycle(Object)does). -
Recycler
protected Recycler(boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = true: it means thatObjectPool.Handle.recycle(Object)is not checking thatobjectis the same which was recycled and assume no other recycling happens concurrently (similar to whatRecycler.EnhancedHandle.unguardedRecycle(Object)does). -
Recycler
USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = trueas stated byRecycler(boolean)and allows to pin the recycler to a specificThread, ifowneris notnull.Since this method has been introduced for performance-sensitive cases it doesn't validate if
get()is called from theownerThread: it assumesget()to never happen concurrently. -
Recycler
protected Recycler(int maxCapacityPerThread) -
Recycler
protected Recycler() -
Recycler
protected Recycler(int chunksSize, int maxCapacityPerThread, boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = trueas stated byRecycler(boolean), but it allows to tune the chunk size used for local pooling. -
Recycler
USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = trueand allows pinning the recycler to a specificThread, as stated byRecycler(Thread, boolean).
It also allows tuning the chunk size used for local pooling and the max capacity per thread.- Throws:
IllegalArgumentException- ifownerisnull.
-
Recycler
Deprecated. -
Recycler
@Deprecated protected Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor, int ratio, int maxDelayedQueuesPerThread) Deprecated. -
Recycler
@Deprecated protected Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor, int ratio, int maxDelayedQueuesPerThread, int delayedQueueRatio) Deprecated. -
Recycler
protected Recycler(int maxCapacityPerThread, int interval, int chunkSize) -
Recycler
protected Recycler(int maxCapacityPerThread, int interval, int chunkSize, boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded =trueas stated byRecycler(boolean). -
Recycler
protected Recycler(int maxCapacityPerThread, int interval, int chunkSize, Thread owner, boolean unguarded) USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded =trueas stated byRecycler(boolean). -
Recycler
private Recycler(int maxCapacityPerThread, int ratio, int chunkSize, boolean useThreadLocalStorage, Thread owner, boolean unguarded)
-
-
Method Details
-
get
-
unpinOwner
Disassociates theRecyclerfrom the currentThreadif it was pinned, seeRecycler(Thread, boolean).Be aware that this method is not thread-safe: it's necessary to allow a
Threadto be garbage collected even ifRecycler.Handles are still referenced by other objects. -
recycle
Deprecated. -
threadLocalSize
final int threadLocalSize() -
newObject
- Parameters:
handle- can NOT be null.
-
Recycler(),Recycler(int),Recycler(int, int, int).