Top Description Fields Constructors Methods
jdk.internal.ref

public abstract Class PhantomCleanable<T>

extends PhantomReference<T>
implements Cleanable
Class Inheritance
All Implemented Interfaces
java.lang.ref.Cleaner.Cleanable
Known Direct Subclasses
java.io.FileCleanable, jdk.internal.ref.CleanerImpl.PhantomCleanableRef, jdk.internal.ref.CleanerImpl.CleanerCleanable
Imports
java.lang.ref.Cleaner, .Reference, .PhantomReference, java.util.Objects

PhantomCleanable subclasses efficiently encapsulate cleanup state and the cleaning action. Subclasses implement the abstract performCleanup() method to provide the cleaning action. When constructed, the object reference and the Cleanable are registered with the Cleaner. The Cleaner invokes clean after the referent becomes phantom reachable.

Field Summary

Modifier and TypeField and Description
private final PhantomCleanable<?>
list

The list of PhantomCleanable; synchronizes insert and remove.

pack-priv PhantomCleanable<?>
next

Hides java.lang.ref.Reference.next.

Links to previous and next in a doubly-linked list.
pack-priv PhantomCleanable<?>
prev

Links to previous and next in a doubly-linked list.

Constructor Summary

AccessConstructor and Description
public
PhantomCleanable(T
the referent to track
referent
,
Cleaner
the Cleaner to register with
cleaner
)

Constructs new PhantomCleanable with non-null referent and non-null cleaner.

pack-priv
PhantomCleanable()

Construct a new root of the list; not inserted.

Method Summary

Modifier and TypeMethod and Description
public final void
clean()

Implements java.lang.ref.Cleaner.Cleanable.clean.

Unregister this PhantomCleanable and invoke performCleanup(), ensuring at-most-once semantics.
public void
clear()

Overrides java.lang.ref.Reference.clear.

Unregister this PhantomCleanable and clear the reference.
public final boolean
private void
insert()

Insert this PhantomCleanable after the list head.

public final boolean
pack-priv boolean

Returns:

true if the list is empty
isListEmpty
()

Returns true if the list's next reference refers to itself.

protected abstract void
performCleanup()

The performCleanup abstract method is overridden to implement the cleaning logic.

private boolean

Returns:

true if Cleanable was removed or false if not because it had already been removed before
remove
()

Remove this PhantomCleanable from the list.

Inherited from java.lang.ref.PhantomReference:
get

Field Detail

listback to summary
private final PhantomCleanable<?> list

The list of PhantomCleanable; synchronizes insert and remove.

nextback to summary
pack-priv PhantomCleanable<?> next

Hides java.lang.ref.Reference.next.

Links to previous and next in a doubly-linked list.

prevback to summary
pack-priv PhantomCleanable<?> prev

Links to previous and next in a doubly-linked list.

Constructor Detail

PhantomCleanableback to summary
public PhantomCleanable(T referent, Cleaner cleaner)

Constructs new PhantomCleanable with non-null referent and non-null cleaner. The cleaner is not retained; it is only used to register the newly constructed Cleanable.

Parameters
referent:T

the referent to track

cleaner:Cleaner

the Cleaner to register with

PhantomCleanableback to summary
pack-priv PhantomCleanable()

Construct a new root of the list; not inserted.

Method Detail

cleanback to summary
public final void clean()

Implements java.lang.ref.Cleaner.Cleanable.clean.

Unregister this PhantomCleanable and invoke performCleanup(), ensuring at-most-once semantics.

Annotations
@Override
clearback to summary
public void clear()

Overrides java.lang.ref.Reference.clear.

Unregister this PhantomCleanable and clear the reference. Due to inherent concurrency, performCleanup() may still be invoked.

Annotations
@Override
enqueueback to summary
public final boolean enqueue()

Overrides java.lang.ref.Reference.enqueue.

This method always throws UnsupportedOperationException. Enqueuing details of Cleaner.Cleanable are a private implementation detail.

Returns:boolean

Doc from java.lang.ref.Reference.enqueue.

true if this reference object was successfully enqueued; false if it was already enqueued or if it was not registered with a queue when it was created

Annotations
@Override
Exceptions
UnsupportedOperationException:
always
insertback to summary
private void insert()

Insert this PhantomCleanable after the list head.

isEnqueuedback to summary
public final boolean isEnqueued()

Overrides java.lang.ref.Reference.isEnqueued.

This method always throws UnsupportedOperationException. Enqueuing details of Cleaner.Cleanable are a private implementation detail.

Returns:boolean

Doc from java.lang.ref.Reference.isEnqueued.

true if and only if this reference object is in its associated queue (if any).

Annotations
@SuppressWarnings:deprecation
@Override
Exceptions
UnsupportedOperationException:
always
isListEmptyback to summary
pack-priv boolean isListEmpty()

Returns true if the list's next reference refers to itself.

Returns:boolean

true if the list is empty

performCleanupback to summary
protected abstract void performCleanup()

The performCleanup abstract method is overridden to implement the cleaning logic. The performCleanup method should not be called except by the clean method which ensures at most once semantics.

removeback to summary
private boolean remove()

Remove this PhantomCleanable from the list.

Returns:boolean

true if Cleanable was removed or false if not because it had already been removed before