Class PooledSoftReference<T>

  • Type Parameters:
    T - the type of the underlying object that the wrapped SoftReference refers to.
    All Implemented Interfaces:
    java.lang.Comparable<PooledObject<T>>, PooledObject<T>

    public class PooledSoftReference<T>
    extends DefaultPooledObject<T>
    Extension of DefaultPooledObject to wrap pooled soft references.

    This class is intended to be thread-safe.

    • Constructor Detail

      • PooledSoftReference

        public PooledSoftReference​(java.lang.ref.SoftReference<T> reference)
        Creates a new PooledSoftReference wrapping the provided reference.
        reference - SoftReference to be managed by the pool
    • Method Detail

      • getObject

        public T getObject()
        Gets the object that the wrapped SoftReference refers to.

        Note that if the reference has been cleared, this method will return null.

        Specified by:
        getObject in interface PooledObject<T>
        getObject in class DefaultPooledObject<T>
        Object referred to by the SoftReference
      • getReference

        public java.lang.ref.SoftReference<T> getReference()
        Gets the SoftReference wrapped by this object.
        underlying SoftReference
      • setReference

        public void setReference​(java.lang.ref.SoftReference<T> reference)
        Sets the wrapped reference.

        This method exists to allow a new, non-registered reference to be held by the pool to track objects that have been checked out of the pool. The actual parameter should be a reference to the same object that getObject() returns before calling this method.

        reference - new reference
      • toString

        public java.lang.String toString()
        Description copied from interface: PooledObject
        Gets a String form of the wrapper for debug purposes. The format is not fixed and may change at any time.
        Specified by:
        toString in interface PooledObject<T>
        toString in class DefaultPooledObject<T>