Top Description Fields Constructors Methods
jnr.ffi.util.ref.internal

public Class Finalizer

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.lang.ref.PhantomReference, .Reference, .ReferenceQueue, .WeakReference, java.lang.reflect.Constructor, .Field, .Method, java.util.logging.Level, .Logger

Thread that finalizes referents. All references should implement com.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.

Field Summary

Modifier and TypeField and Description
private static final String
FINALIZABLE_REFERENCE

Name of FinalizableReference.class.

private final WeakReference<Class<?>>
private final PhantomReference<Object>
private static final Field
private static final Constructor<Thread>
private static final Logger
private final ReferenceQueue<Object>
private Thread

Constructor Summary

AccessConstructor and Description
private
Finalizer(Class<?> finalizableReferenceClass, Object frq)

Constructs a new finalizer thread.

Method Summary

Modifier and TypeMethod and Description
private boolean
cleanUp(Reference<?> reference)

Cleans up a single reference.

private Method
getFinalizeReferentMethod()

Looks up FinalizableReference.finalizeReferent() method.

public static Constructor<Thread>
public static Field
public void
run()

Implements java.lang.Runnable.run.

Loops continuously, pulling references off the queue and cleaning them up.
public void
public static ReferenceQueue<Object>

Returns:

ReferenceQueue which Finalizer will poll
startFinalizer
(Class<?>
FinalizableReference.class
finalizableReferenceClass
,
Object
reference to instance of FinalizableReferenceQueue that started this thread
frq
)

Starts the Finalizer thread.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FINALIZABLE_REFERENCEback to summary
private static final String FINALIZABLE_REFERENCE

Name of FinalizableReference.class.

finalizableReferenceClassReferenceback to summary
private final WeakReference<Class<?>> finalizableReferenceClassReference
frqReferenceback to summary
private final PhantomReference<Object> frqReference
inheritableThreadLocalsback to summary
private static final Field inheritableThreadLocals
inheritableThreadlocalsConstructorback to summary
private static final Constructor<Thread> inheritableThreadlocalsConstructor
loggerback to summary
private static final Logger logger
queueback to summary
private final ReferenceQueue<Object> queue
threadback to summary
private Thread thread

Constructor Detail

Finalizerback to summary
private Finalizer(Class<?> finalizableReferenceClass, Object frq)

Constructs a new finalizer thread.

Method Detail

cleanUpback to summary
private boolean cleanUp(Reference<?> reference)

Cleans up a single reference. Catches and logs all throwables.

getFinalizeReferentMethodback to summary
private Method getFinalizeReferentMethod()

Looks up FinalizableReference.finalizeReferent() method.

getInheritableThreadLocalsConstructorback to summary
public static Constructor<Thread> getInheritableThreadLocalsConstructor()
getInheritableThreadLocalsFieldback to summary
public static Field getInheritableThreadLocalsField()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Loops continuously, pulling references off the queue and cleaning them up.

Annotations
@SuppressWarnings:InfiniteLoopStatement
@Override
startback to summary
public void start()
startFinalizerback to summary
public static ReferenceQueue<Object> startFinalizer(Class<?> finalizableReferenceClass, Object frq)

Starts the Finalizer thread. FinalizableReferenceQueue calls this method reflectively.

Parameters
finalizableReferenceClass:Class<?>

FinalizableReference.class

frq:Object

reference to instance of FinalizableReferenceQueue that started this thread

Returns:ReferenceQueue<Object>

ReferenceQueue which Finalizer will poll