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
  • Method Details

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