APIdia Launch Partner
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
pack-priv int
index

Index of this PhantomCleanable in the list node.

private final CleanerImpl.CleanableList
list

The list of PhantomCleanable; synchronizes insert and remove.

pack-priv CleanerImpl.CleanableList.Node
node

Node for this PhantomCleanable in the 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.

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
public final boolean
protected abstract void
performCleanup()

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

Inherited from java.lang.ref.PhantomReference:
get

Field Detail

indexback to summary
pack-priv int index

Index of this PhantomCleanable in the list node. Synchronized by the same lock as the list itself.

listback to summary
private final CleanerImpl.CleanableList list

The list of PhantomCleanable; synchronizes insert and remove.

nodeback to summary
pack-priv CleanerImpl.CleanableList.Node node

Node for this PhantomCleanable in the list. Synchronized by the same lock as the list itself.

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

Annotations
@SuppressWarnings:this-escape

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.

Annotations
@Override
Exceptions
UnsupportedOperationException:
always
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.

Annotations
@SuppressWarnings:deprecation
@Override
Exceptions
UnsupportedOperationException:
always
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.