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
Type Parameters
<T>
the type of the reference object
Imports
java.util.function.Consumer, jdk.internal.misc.VM, jdk.internal.vm.Continuation, .ContinuationSupport

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
private static class

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
ReferenceQueue()

Constructs a new reference-object queue.

Method Summary

Modifier and TypeMethod and Description
private void
pack-priv boolean
enqueue(Reference<? extends T> r)

private 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.

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.

private 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.

private Reference<? extends T>
remove0(long timeout)

private Reference<? extends T>
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ENQUEUEDback to summary
pack-priv static final ReferenceQueue<Object> ENQUEUED
lockback to summary
private final ReferenceQueue.Lock lock
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.

Method Detail

enablePreemptback to summary
private void enablePreempt()
enqueueback to summary
pack-priv boolean enqueue(Reference<? extends T> r)
enqueue0back to summary
private 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.

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
private 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
private Reference<? extends T> remove0(long timeout) throws InterruptedException
remove0back to summary
private Reference<? extends T> remove0() throws InterruptedException
tryDisablePreemptback to summary
private boolean tryDisablePreempt()
java.lang.ref back to summary

private Class ReferenceQueue.Lock

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
private
Lock()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Lockback to summary
private Lock()
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
private
Null()

Method Summary

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

Constructor Detail

Nullback to summary
private Null()

Method Detail

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

Overrides java.lang.ref.ReferenceQueue.enqueue.

Annotations
@Override