Class LazyCleanerImpl

  • All Implemented Interfaces:
    LazyCleaner

    public class LazyCleanerImpl
    extends java.lang.Object
    implements LazyCleaner
    LazyCleaner is a utility class that allows to register objects for deferred cleanup.

    This is the Java 8 compatible implementation that uses PhantomReferences and ForkJoinPool for deferred cleanup operations.

    On Java 11+, this class is replaced by a version that uses the native Cleaner API via the multi-release JAR mechanism.

    Note: this is a driver-internal class

    • Constructor Detail

      • LazyCleanerImpl

        public LazyCleanerImpl​(java.lang.String threadName,
                               java.time.Duration threadTtl)
        Creates a LazyCleaner with the specified configuration.
        Parameters:
        threadName - the name for the cleanup thread
        threadTtl - the maximum time the cleanup thread will wait for references
    • Method Detail

      • getInstance

        public static LazyCleanerImpl getInstance()
        Returns a default cleaner instance.

        Note: this is driver-internal API.

        Returns:
        the instance of LazyCleaner
      • register

        public <T extends java.lang.Throwable> LazyCleaner.Cleanable<T> register​(java.lang.Object obj,
                                                                                 LazyCleaner.CleaningAction<T> action)
        Description copied from interface: LazyCleaner
        Registers an object for cleanup when it becomes phantom reachable.
        Specified by:
        register in interface LazyCleaner
        Type Parameters:
        T - the type of exception that can be thrown during cleanup
        Parameters:
        obj - the object to monitor for cleanup (should not be the same as action)
        action - the action to perform when the object becomes unreachable
        Returns:
        a Cleanable that can be used to manually trigger cleanup
      • isThreadRunning

        public boolean isThreadRunning()
        Returns whether the cleanup thread is currently running.
        Returns:
        true if cleanup operations are active