Package org.postgresql.util
Class LazyCleanerImpl
java.lang.Object
org.postgresql.util.LazyCleanerImpl
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.postgresql.util.LazyCleaner
LazyCleaner.Cleanable<T extends Throwable>, LazyCleaner.CleaningAction<T extends Throwable> -
Constructor Summary
ConstructorsConstructorDescriptionLazyCleanerImpl(String threadName, Duration threadTtl) Creates a LazyCleaner with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic LazyCleanerImplReturns a default cleaner instance.booleanReturns whether the cleanup thread is currently running.<T extends Throwable>
LazyCleaner.Cleanable<T>register(Object obj, LazyCleaner.CleaningAction<T> action) Registers an object for cleanup when it becomes phantom reachable.
-
Constructor Details
-
LazyCleanerImpl
Creates a LazyCleaner with the specified configuration.- Parameters:
threadName- the name for the cleanup threadthreadTtl- the maximum time the cleanup thread will wait for references
-
-
Method Details
-
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:LazyCleanerRegisters an object for cleanup when it becomes phantom reachable.- Specified by:
registerin interfaceLazyCleaner- 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
-