Name
ReferenceQueue<T>
Synopsis
This class represents a queue (or linked
list) of Reference
objects that have been enqueued
because the garbage collector has determined that the referent
objects to which they refer are no longer adequately reachable. It
serves as a notification system for object-reachability changes. Use
poll( )
to return the first
Reference
object on the queue; the method returns
null
if the queue is empty. Use remove(
)
to return the first element on the queue, or, if the
queue is empty, to wait for a Reference
object to
be enqueued. You can create as many ReferenceQueue
objects as needed. Specify a ReferenceQueue
for a
Reference
object by passing it to the
SoftReference( )
, WeakReference(
)
, or PhantomReference( )
constructor.
A ReferenceQueue
is
required to use PhantomReference
objects. It is
optional with SoftReference
and
WeakReference
objects; for these classes, the
get( )
method returns null
if
the referent object is no longer adequately reachable.
public class ReferenceQueue<T> { // Public Constructors public ReferenceQueue( ); // Public Instance Methods public Reference<? extends T> poll( ); public Reference<? extends T> remove( ) throws InterruptedException; public Reference<? extends T> remove(long timeout) throws IllegalArgumentException, InterruptedException; }
Passed To
PhantomReference.PhantomReference( )
,
SoftReference.SoftReference( )
,
WeakReference.WeakReference( )
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.