Class WeakPool<B>

java.lang.Object
org.cojen.tupl.util.WeakPool<B>

public class WeakPool<B> extends Object
Utility for sharing a small set of poolable objects (like buffers) which are weakly referenced. Only one thread at a time can access pooled objects, but any number of threads can release pooled objects.
  • Constructor Details

    • WeakPool

      public WeakPool()
  • Method Details

    • tryAccess

      public WeakPool.Entry<B> tryAccess()
      Returns an available pooled entry if any exist. If an entry is returned but the pooled object is null, discard the entry and try again. A strong reference to the pooled object must be maintained to ensure that it doesn't vanish too soon.

      Note: This method can only be called by one thread at a time.

    • newEntry

      public WeakPool.Entry<B> newEntry(B obj)
      Create a new pooled entry which refers to the given object. This method is thread-safe.