com.caucho.hessian.util
Class HessianFreeList<T>

java.lang.Object
  extended by com.caucho.hessian.util.HessianFreeList<T>

public final class HessianFreeList<T>
extends java.lang.Object

FreeList provides a simple class to manage free objects. This is useful for large data structures that otherwise would gobble up huge GC time.

The free list is bounded. Freeing an object when the list is full will do nothing.


Field Summary
private  java.util.concurrent.atomic.AtomicReferenceArray<T> _freeStack
           
private  java.util.concurrent.atomic.AtomicInteger _top
           
 
Constructor Summary
HessianFreeList(int size)
          Create a new free list.
 
Method Summary
 T allocate()
          Try to get an object from the free list.
 boolean allowFree(T obj)
           
 boolean checkDuplicate(T obj)
          Debugging to see if the object has already been freed.
 boolean free(T obj)
          Frees the object.
 void freeCareful(T obj)
          Frees the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_freeStack

private final java.util.concurrent.atomic.AtomicReferenceArray<T> _freeStack

_top

private final java.util.concurrent.atomic.AtomicInteger _top
Constructor Detail

HessianFreeList

public HessianFreeList(int size)
Create a new free list.

Parameters:
initialSize - maximum number of free objects to store.
Method Detail

allocate

public T allocate()
Try to get an object from the free list. Returns null if the free list is empty.

Returns:
the new object or null.

free

public boolean free(T obj)
Frees the object. If the free list is full, the object will be garbage collected.

Parameters:
obj - the object to be freed.

allowFree

public boolean allowFree(T obj)

freeCareful

public void freeCareful(T obj)
Frees the object. If the free list is full, the object will be garbage collected.

Parameters:
obj - the object to be freed.

checkDuplicate

public boolean checkDuplicate(T obj)
Debugging to see if the object has already been freed.



Copyright 2003-2011. All Rights Reserved.