javolution37.javolution.realtime
Class ObjectPool<T>
- java.lang.Object
-
- javolution37.javolution.realtime.ObjectPool<T>
-
public abstract class ObjectPool<T> extends java.lang.ObjectThis abstract class represents an object pool managed by a
PoolContext.Pool objects are always allocated in the same memory area as the pool object itself. In other words,
NoHeapRealtimeThreadexecuting inScopedMemorycan safely use pools allocated inImmortalMemory.
-
-
Field Summary
Fields Modifier and Type Field and Description static ObjectPoolNULLHolds a pool returningnullvalues.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description ObjectPool<T>getOuter()Returns the outer pool of this pool.java.lang.ThreadgetUser()Returns the current user of this pool ornullif none.booleaninUse()Indicates if this pool is in use.booleanisLocal()Indicates if this pool is actively used by the current thread.abstract Tnext()Returns the next available object from this pool.abstract voidrecycle(T obj)Recycles the specified object.abstract intsize()Returns the number of objects held by this pool.
-
-
-
Field Detail
-
NULL
public static final ObjectPool NULL
Holds a pool returningnullvalues.
-
-
Method Detail
-
getUser
public final java.lang.Thread getUser()
Returns the current user of this pool ornullif none.- Returns:
- the pool current user.
-
isLocal
public final boolean isLocal()
Indicates if this pool is actively used by the current thread. The framework ensures that local pools are visible to their users only (concurrent executions are performed in an inner pool context). Operations on local pools are therefore thread-safe without requiring synchronization.- Returns:
trueif this pool is local for the current thread;falseotherwise.- Throws:
JavolutionError- if this operation is called upon a pool not currentlyin use.
-
inUse
public final boolean inUse()
Indicates if this pool is in use. A pool can be in use and not having a current user if the user has entered an inner pool.- Returns:
trueif at least one thread has been allocating from this pool;falseif this pool is not being used at all (e.g. inner pool).
-
getOuter
public final ObjectPool<T> getOuter()
Returns the outer pool of this pool.- Returns:
- the outer pool or
nullif the outer is the heap.
-
size
public abstract int size()
Returns the number of objects held by this pool.- Returns:
- this pool size.
-
next
public abstract T next()
Returns the next available object from this pool. If there is none, a new object is allocated from the same memory area as this pool, added to the pool and then returned.- Returns:
- the next available object from this pool.
-
recycle
public abstract void recycle(T obj)
Recycles the specified object. Callers should make sure that the recycled object is not going to be referenced anymore (in a heap context it would be garbage collected).- Parameters:
obj- the object to recycle to this pool.- Throws:
java.lang.IllegalArgumentException- if the specified object do not belong to the pool.
-
-
DMelt 3.0 © DataMelt by jWork.ORG