Java Reference
In-Depth Information
Removes and returns the next reference object from this
queue, or null if the queue is empty.
public Reference<? extends T> remove() tHRows InterruptedException
Removes and returns the next reference object from this
queue. This method blocks indefinitely until a reference object
is available from the queue.
public Reference<? extends T> remove(long timeout) throws Interrup-
tedException
Removes and returns the next reference object from this
queue. This method blocks until a reference object is available
from the queue or the specified time-out period elapses. If the
time-out expires, null is returned. A time-out of zero means
wait indefinitely.
The poll method allows a thread to query the existence of a reference
in a queue, taking action only if one is present, as in the example. The
remove methods are intended for more complex (and rare) situations in
which a dedicated thread is responsible for removing references from
the queue and taking the appropriate actionthe blocking behavior of
these methods is the same as that defined by Object.wait (as discussed
from page 354 ). You can ask whether a particular reference is in a queue
via its isEnqueued method. You can force a reference into its queue by
calling its enqueue method, but usually this is done by the garbage col-
lector.
Reference queues are used with phantom references to determine when
an object is about to be reclaimed. A phantom reference never lets you
reach the object, even when it is otherwise reachable: Its get method
always returns null . In effect it is the safest way to find out about a col-
lected objecta weak or soft reference will be enqueued after an object is
finalizable; a phantom reference is enqueued after the referent has been
finalized and, therefore only after the last possible time that the object
can do something. If you can, you should generally use a phantom ref-
 
Search WWH ::




Custom Search