public class Cleaner extends Object
This is a more-or-less drop-in replacement for the
java.lang.ref.Cleaner
class introduced in Java 9.
If the target platform for this package gets upgraded to Java 9 or greater,
this class can be retired in favour of the JRE implementation.
The getInstance()
method lazily constructs a singleton instance,
which is probably suitable for most purposes. But you can construct
your own if you want.
Modifier and Type | Class and Description |
---|---|
static interface |
Cleaner.Cleanable
Cleanable represents an object and a cleaning action registered
in a Cleaner.
|
Constructor and Description |
---|
Cleaner()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static Cleaner |
getInstance()
Returns a lazily constructed singleton instance of this class.
|
Cleaner.Cleanable |
register(Object obj,
Runnable action)
Registers an object and a cleaning action to run when
the object becomes phantom reachable.
|
public Cleaner.Cleanable register(Object obj, Runnable action)
obj
- the object to monitoraction
- a Runnable to invoke when the object becomes
phantom reachablepublic static Cleaner getInstance()
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.