Package com.couchbase.client.core.util
Class Jdk8Cleaner
- java.lang.Object
-
- com.couchbase.client.core.util.Jdk8Cleaner
-
@Internal public class Jdk8Cleaner extends Object
Approximates Java 9's java.lang.ref.Cleaner
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Jdk8Cleaner.Cleanable
An object and a cleaning action registered in a Cleaner.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Jdk8Cleaner
create(ThreadFactory factory)
Jdk8Cleaner.Cleanable
register(Object obj, Runnable cleaningAction)
Executes the given cleaning action when the object becomes phantom reachable.static void
registerWithOneShotCleaner(Object obj, Runnable cleanupTask)
Creates a new cleaner, and registers the given cleanup action to run when the given object becomes phantom reachable.
-
-
-
Method Detail
-
create
public static Jdk8Cleaner create(ThreadFactory factory)
-
registerWithOneShotCleaner
public static void registerWithOneShotCleaner(Object obj, Runnable cleanupTask)
Creates a new cleaner, and registers the given cleanup action to run when the given object becomes phantom reachable.The cleaner's thread terminates after the given cleanup task is executed.
The cleaning action should generally not be a lambda, since it's easy to accidentally capture a reference to the object, preventing it from ever becoming phantom reachable.
-
register
public Jdk8Cleaner.Cleanable register(Object obj, Runnable cleaningAction)
Executes the given cleaning action when the object becomes phantom reachable.The cleaning action should generally not be a lambda, since it's easy to accidentally capture a reference to the object, preventing it from ever becoming phantom reachable.
-
-