Class LazyCleanerImpl

java.lang.Object
org.postgresql.util.LazyCleanerImpl
All Implemented Interfaces:
LazyCleaner

public class LazyCleanerImpl extends 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 Details

    • LazyCleanerImpl

      public LazyCleanerImpl(String threadName, 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 Details

    • 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 Throwable> LazyCleaner.Cleanable<T> register(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