J avolution v3.7 (J2SE 1.5+)

javolution.realtime
Class ObjectPool<T>

java.lang.Object
  extended by javolution.realtime.ObjectPool<T>

public abstract class ObjectPool<T>
extends java.lang.Object

This 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, NoHeapRealtimeThread executing in ScopedMemory can safely use pools allocated in ImmortalMemory.

Version:
3.7, December 20, 2005
Author:
Jean-Marie Dautelle

Field Summary
static ObjectPool NULL
          Holds a pool returning null values.
 
Constructor Summary
protected ObjectPool()
          Default constructor.
 
Method Summary
protected abstract  void clearAll()
          Removes all objects (used and new) from this pool.
 ObjectPool<T> getOuter()
          Returns the outer pool of this pool.
 java.lang.Thread getUser()
          Returns the current user of this pool or null if none.
 boolean inUse()
          Indicates if this pool is in use.
 boolean isLocal()
          Indicates if this pool is actively used by the current thread.
abstract  T next()
          Returns the next available object from this pool.
abstract  void recycle(T obj)
          Recycles the specified object.
protected abstract  void recycleAll()
          Recycles all the objects of this pool (all used objects become new).
abstract  int size()
          Returns the number of objects held by this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final ObjectPool NULL
Holds a pool returning null values.

Constructor Detail

ObjectPool

protected ObjectPool()
Default constructor.

Method Detail

getUser

public final java.lang.Thread getUser()
Returns the current user of this pool or null if 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:
true if this pool is local for the current thread; false otherwise.
Throws:
javolution.JavolutionError - if this operation is called upon a pool not currently in 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:
true if at least one thread has been allocating from this pool; false if 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 null if 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.

recycleAll

protected abstract void recycleAll()
Recycles all the objects of this pool (all used objects become new).

Note: This method is called upon exit of a pool context for which this pool has been used.


clearAll

protected abstract void clearAll()
Removes all objects (used and new) from this pool.

Note: This method is called upon clearing of the pool context this pool belongs to.


J avolution v3.7 (J2SE 1.5+)

Copyright © 2006 Javolution.