Top Description Inners Fields Constructors Methods
java.lang.ref

public Class ReferenceQueue<T>

extends Object
Class Inheritance
Known Direct Subclasses
java.lang.ref.ReferenceQueue.Null, java.lang.ref.NativeReferenceQueue
Type Parameters
<T>
the type of the reference object
Imports
java.util.concurrent.TimeUnit, java.util.concurrent.locks.Condition, .ReentrantLock, java.util.function.Consumer, jdk.internal.misc.VM

Reference queues, to which registered reference objects are appended by the garbage collector after the appropriate reachability changes are detected.

Memory consistency effects: The enqueueing of a reference to a queue (by the garbage collector, or by a successful call to Reference#enqueue) happens-before the reference is removed from the queue by ReferenceQueue#poll or ReferenceQueue#remove.

Author
Mark Reinhold
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final ReferenceQueue<Object>
private volatile Reference<? extends T>
private final ReentrantLock
private final Condition
pack-priv static final ReferenceQueue<Object>
private long

Constructor Summary

AccessConstructor and Description
public
ReferenceQueue()

Constructs a new reference-object queue.

pack-priv
ReferenceQueue(int dummy)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
await(long timeoutMillis)

pack-priv boolean
enqueue(Reference<? extends T> r)

pack-priv final boolean
enqueue0(Reference<? extends T> r)

pack-priv void
forEach(Consumer<? super Reference<? extends T>> action)

Iterate queue and invoke given action with each Reference.

pack-priv final boolean
public Reference<? extends T>

Returns:

A reference object, if one was immediately available, otherwise null
poll
()

Polls this queue to see if a reference object is available.

pack-priv final Reference<? extends T>
public Reference<? extends T>

Returns:

A reference object, if one was available within the specified timeout period, otherwise null
remove
(long
If positive, block for up to timeout milliseconds while waiting for a reference to be added to this queue. If zero, block indefinitely.
timeout
)

Removes the next reference object in this queue, blocking until either one becomes available or the given timeout period expires.

public Reference<? extends T>

Returns:

A reference object, blocking until one becomes available
remove
()

Removes the next reference object in this queue, blocking until one becomes available.

pack-priv final Reference<? extends T>
remove0(long timeout)

pack-priv final Reference<? extends T>
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ENQUEUEDback to summary
pack-priv static final ReferenceQueue<Object> ENQUEUED
lockback to summary
private final ReentrantLock lock
notEmptyback to summary
private final Condition notEmpty
NULLback to summary
pack-priv static final ReferenceQueue<Object> NULL
queueLengthback to summary
private long queueLength

Constructor Detail

ReferenceQueueback to summary
public ReferenceQueue()

Constructs a new reference-object queue.

ReferenceQueueback to summary
pack-priv ReferenceQueue(int dummy)

Method Detail

awaitback to summary
pack-priv void await() throws InterruptedException
awaitback to summary
pack-priv void await(long timeoutMillis) throws InterruptedException
enqueueback to summary
pack-priv boolean enqueue(Reference<? extends T> r)
enqueue0back to summary
pack-priv final boolean enqueue0(Reference<? extends T> r)
forEachback to summary
pack-priv void forEach(Consumer<? super Reference<? extends T>> action)

Iterate queue and invoke given action with each Reference. Suitable for diagnostic purposes.

Warning

any use of this method should make sure to not retain the referents of iterated references (in case of FinalReference(s)) so that their life is not prolonged more than necessary.

headIsNullback to summary
pack-priv final boolean headIsNull()
pollback to summary
public Reference<? extends T> poll()

Polls this queue to see if a reference object is available. If one is available without further delay then it is removed from the queue and returned. Otherwise this method immediately returns null.

Returns:Reference<? extends T>

A reference object, if one was immediately available, otherwise null

See Also
java.lang.ref.Reference#enqueue()
poll0back to summary
pack-priv final Reference<? extends T> poll0()
removeback to summary
public Reference<? extends T> remove(long timeout) throws InterruptedException

Removes the next reference object in this queue, blocking until either one becomes available or the given timeout period expires.

This method does not offer real-time guarantees: It schedules the timeout as if by invoking the Object#wait(long) method.

Parameters
timeout:long

If positive, block for up to timeout milliseconds while waiting for a reference to be added to this queue. If zero, block indefinitely.

Returns:Reference<? extends T>

A reference object, if one was available within the specified timeout period, otherwise null

Exceptions
InterruptedException:
If the timeout wait is interrupted
IllegalArgumentException:
If the value of the timeout argument is negative
See Also
java.lang.ref.Reference#enqueue()
removeback to summary
public Reference<? extends T> remove() throws InterruptedException

Removes the next reference object in this queue, blocking until one becomes available.

Returns:Reference<? extends T>

A reference object, blocking until one becomes available

Exceptions
InterruptedException:
If the wait is interrupted
See Also
java.lang.ref.Reference#enqueue()
remove0back to summary
pack-priv final Reference<? extends T> remove0(long timeout) throws IllegalArgumentException, InterruptedException
remove0back to summary
pack-priv final Reference<? extends T> remove0() throws InterruptedException
signalback to summary
pack-priv void signal()
java.lang.ref back to summary

private Class ReferenceQueue.Null

extends ReferenceQueue<Object>
Class Inheritance

Field Summary

Inherited from java.lang.ref.ReferenceQueue:
ENQUEUEDNULL

Constructor Summary

AccessConstructor and Description
public
Null()

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
Inherited from java.lang.ref.ReferenceQueue:
awaitawaitenqueue0forEachheadIsNullpollpoll0removeremoveremove0remove0signal

Constructor Detail

Nullback to summary
public Null()

Method Detail

enqueueback to summary
pack-priv boolean enqueue(Reference<?> r)

Overrides java.lang.ref.ReferenceQueue.enqueue.

Annotations
@Override