Package jnr.ffi.util.ref
Class FinalizableReferenceQueue
- java.lang.Object
-
- jnr.ffi.util.ref.FinalizableReferenceQueue
-
public class FinalizableReferenceQueue extends java.lang.Object
A reference queue with an associated background thread that dequeues references and invokesFinalizableReference.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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
FinalizableReferenceQueue.DecoupledLoader
Try to load Finalizer in its own class loader.(package private) static class
FinalizableReferenceQueue.DirectLoader
Loads Finalizer directly using the current class loader.(package private) static interface
FinalizableReferenceQueue.FinalizerLoader
Loads Finalizer.class.(package private) static class
FinalizableReferenceQueue.SystemLoader
Tries to load Finalizer from the system class loader.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
FINALIZER_CLASS_NAME
private static java.util.Map<FinalizableReferenceQueue,java.lang.Boolean>
finalizerQueues
private static java.util.logging.Logger
logger
(package private) java.lang.ref.ReferenceQueue<java.lang.Object>
queue
The actual reference queue that our background thread will poll.private static java.lang.reflect.Method
startFinalizer
Reference to Finalizer.startFinalizer().(package private) boolean
threadStarted
Whether or not the background thread started successfully.
-
Constructor Summary
Constructors Constructor Description FinalizableReferenceQueue()
Constructs a new queue.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
cleanUp()
Repeatedly dequeues references from the queue and invokesFinalizableReference.finalizeReferent()
on them until the queue is empty.static void
cleanUpAll()
(package private) static java.lang.reflect.Method
getStartFinalizer(java.lang.Class<?> finalizer)
Looks up Finalizer.startFinalizer().private static java.lang.Class<?>
loadFinalizer(FinalizableReferenceQueue.FinalizerLoader... loaders)
Iterates through the given loaders until it finds one that can load Finalizer.private void
pollReferenceQueue()
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
FINALIZER_CLASS_NAME
private static final java.lang.String FINALIZER_CLASS_NAME
- See Also:
- Constant Field Values
-
startFinalizer
private static final java.lang.reflect.Method startFinalizer
Reference to Finalizer.startFinalizer().
-
finalizerQueues
private static final java.util.Map<FinalizableReferenceQueue,java.lang.Boolean> finalizerQueues
-
queue
final java.lang.ref.ReferenceQueue<java.lang.Object> queue
The actual reference queue that our background thread will poll.
-
threadStarted
final boolean threadStarted
Whether or not the background thread started successfully.
-
-
Method Detail
-
cleanUp
void cleanUp()
Repeatedly dequeues references from the queue and invokesFinalizableReference.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 java.lang.Class<?> loadFinalizer(FinalizableReferenceQueue.FinalizerLoader... loaders)
Iterates through the given loaders until it finds one that can load Finalizer.- Returns:
- Finalizer.class
-
getStartFinalizer
static java.lang.reflect.Method getStartFinalizer(java.lang.Class<?> finalizer)
Looks up Finalizer.startFinalizer().
-
cleanUpAll
public static void cleanUpAll()
-
-