Class Finalizer
- java.lang.Object
-
- jnr.ffi.util.ref.internal.Finalizer
-
- All Implemented Interfaces:
java.lang.Runnable
public class Finalizer extends java.lang.Object implements java.lang.Runnable
Thread that finalizes referents. All references should implementcom.google.common.base.FinalizableReference
.While this class is public, we consider it to be *internal* and not part of our published API. It is public so we can access it reflectively across class loaders in secure environments.
This class can't depend on other Google Collections code. If we were to load this class in the same class loader as the rest of Google Collections, this thread would keep an indirect strong reference to the class loader and prevent it from being garbage collected. This poses a problem for environments where you want to throw away the class loader. For example, dynamically reloading a web application or unloading an OSGi bundle.
com.google.common.base.FinalizableReferenceQueue
loads this class in its own class loader. That way, this class doesn't prevent the main class loader from getting garbage collected, and this class can detect when the main class loader has been garbage collected and stop itself.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.reflect.Constructor<java.lang.Thread>
getInheritableThreadLocalsConstructor()
static java.lang.reflect.Field
getInheritableThreadLocalsField()
void
run()
Loops continuously, pulling references off the queue and cleaning them up.void
start()
static java.lang.ref.ReferenceQueue<java.lang.Object>
startFinalizer(java.lang.Class<?> finalizableReferenceClass, java.lang.Object frq)
Starts the Finalizer thread.
-
-
-
Method Detail
-
startFinalizer
public static java.lang.ref.ReferenceQueue<java.lang.Object> startFinalizer(java.lang.Class<?> finalizableReferenceClass, java.lang.Object frq)
Starts the Finalizer thread. FinalizableReferenceQueue calls this method reflectively.- Parameters:
finalizableReferenceClass
- FinalizableReference.classfrq
- reference to instance of FinalizableReferenceQueue that started this thread- Returns:
- ReferenceQueue which Finalizer will poll
-
start
public void start()
-
run
public void run()
Loops continuously, pulling references off the queue and cleaning them up.- Specified by:
run
in interfacejava.lang.Runnable
-
getInheritableThreadLocalsField
public static java.lang.reflect.Field getInheritableThreadLocalsField()
-
getInheritableThreadLocalsConstructor
public static java.lang.reflect.Constructor<java.lang.Thread> getInheritableThreadLocalsConstructor()
-
-