Class FinalizableReferenceQueue

java.lang.Object
jnr.ffi.util.ref.FinalizableReferenceQueue

public class FinalizableReferenceQueue extends Object
A reference queue with an associated background thread that dequeues references and invokes FinalizableReference.finalizeReferent() on them.

Keep a strong reference to this object until all of the associated referents have been finalized. If this object is garbage collected earlier, the backing thread will not invoke finalizeReferent() on the remaining references.

Since:
2.0 (imported from Google Collections Library)
  • Field Details

    • logger

      private static final Logger logger
    • FINALIZER_CLASS_NAME

      private static final String FINALIZER_CLASS_NAME
      See Also:
    • startFinalizer

      private static final Method startFinalizer
      Reference to Finalizer.startFinalizer().
    • finalizerQueues

      private static final Map<FinalizableReferenceQueue,Boolean> finalizerQueues
    • queue

      final ReferenceQueue<Object> queue
      The actual reference queue that our background thread will poll.
    • threadStarted

      final boolean threadStarted
      Whether or not the background thread started successfully.
  • Constructor Details

    • FinalizableReferenceQueue

      public FinalizableReferenceQueue()
      Constructs a new queue.
  • Method Details

    • cleanUp

      void cleanUp()
      Repeatedly dequeues references from the queue and invokes FinalizableReference.finalizeReferent() on them until the queue is empty. This method is a no-op if the background thread was created successfully.
    • pollReferenceQueue

      private void pollReferenceQueue()
    • loadFinalizer

      private static Class<?> loadFinalizer(FinalizableReferenceQueue.FinalizerLoader... loaders)
      Iterates through the given loaders until it finds one that can load Finalizer.
      Returns:
      Finalizer.class
    • getStartFinalizer

      static Method getStartFinalizer(Class<?> finalizer)
      Looks up Finalizer.startFinalizer().
    • cleanUpAll

      public static void cleanUpAll()