Package io.netty.util
Class Recycler<T>
- java.lang.Object
-
- io.netty.util.Recycler<T>
-
- Type Parameters:
T
- the type of the pooled object
public abstract class Recycler<T> extends java.lang.Object
Light-weight object pool based on a thread-local stack.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Recycler.EnhancedHandle<T>
static interface
Recycler.Handle<T>
-
Constructor Summary
Constructors Modifier Constructor Description protected
Recycler()
protected
Recycler(boolean unguarded)
USE IT CAREFULLY!protected
Recycler(int maxCapacityPerThread)
protected
Recycler(int maxCapacity, boolean unguarded)
USE IT CAREFULLY!protected
Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor)
Deprecated.protected
Recycler(int chunksSize, int maxCapacityPerThread, boolean unguarded)
USE IT CAREFULLY!protected
Recycler(int maxCapacityPerThread, int interval, int chunkSize)
protected
Recycler(int maxCapacityPerThread, int interval, int chunkSize, boolean unguarded)
USE IT CAREFULLY!protected
Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor, int ratio, int maxDelayedQueuesPerThread)
Deprecated.protected
Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor, int ratio, int maxDelayedQueuesPerThread, int delayedQueueRatio)
Deprecated.protected
Recycler(int maxCapacityPerThread, int interval, int chunkSize, java.lang.Thread owner, boolean unguarded)
USE IT CAREFULLY!protected
Recycler(int chunkSize, int maxCapacityPerThread, java.lang.Thread owner, boolean unguarded)
USE IT CAREFULLY!protected
Recycler(java.lang.Thread owner, boolean unguarded)
USE IT CAREFULLY!
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description T
get()
protected abstract T
newObject(Recycler.Handle<T> handle)
boolean
recycle(T o, Recycler.Handle<T> handle)
Deprecated.static void
unpinOwner(Recycler<?> recycler)
-
-
-
Constructor Detail
-
Recycler
protected Recycler(int maxCapacity, boolean unguarded)
USE IT CAREFULLY!
This is creating a shareableRecycler
whichget()
can be called concurrently from differentThread
s.
UsuallyRecycler
s 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 thatobject
is 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 thatobject
is the same which was recycled and assume no other recycling happens concurrently (similar to whatRecycler.EnhancedHandle.unguardedRecycle(Object)
does).
-
Recycler
protected Recycler(java.lang.Thread owner, boolean unguarded)
USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = true
as stated byRecycler(boolean)
and allows to pin the recycler to a specificThread
, ifowner
is notnull
.Since this method has been introduced for performance-sensitive cases it doesn't validate if
get()
is called from theowner
Thread
: 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 = true
as stated byRecycler(boolean)
, but it allows to tune the chunk size used for local pooling.
-
Recycler
protected Recycler(int chunkSize, int maxCapacityPerThread, java.lang.Thread owner, boolean unguarded)
USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded = true
and 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:
java.lang.IllegalArgumentException
- ifowner
isnull
.
-
Recycler
@Deprecated protected Recycler(int maxCapacityPerThread, int maxSharedCapacityFactor)
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 =true
as stated byRecycler(boolean)
.
-
Recycler
protected Recycler(int maxCapacityPerThread, int interval, int chunkSize, java.lang.Thread owner, boolean unguarded)
USE IT CAREFULLY!
This is NOT enforcing pooled instances states to be validated ifunguarded =true
as stated byRecycler(boolean)
.
-
-
Method Detail
-
get
public final T get()
-
unpinOwner
public static void unpinOwner(Recycler<?> recycler)
Disassociates theRecycler
from the currentThread
if it was pinned, seeRecycler(Thread, boolean)
.Be aware that this method is not thread-safe: it's necessary to allow a
Thread
to be garbage collected even ifRecycler.Handle
s are still referenced by other objects.
-
recycle
@Deprecated public final boolean recycle(T o, Recycler.Handle<T> handle)
Deprecated.
-
newObject
protected abstract T newObject(Recycler.Handle<T> handle)
- Parameters:
handle
- can NOT be null.
-
-