Package org.postgresql.util
Class LazyCleanerImpl
- java.lang.Object
-
- org.postgresql.util.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
CleanerAPI via the multi-release JAR mechanism.Note: this is a driver-internal class
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classLazyCleanerImpl.Node<T extends java.lang.Throwable>private static classLazyCleanerImpl.RefQueueBlocker<T>RefQueueBlocker retrieves references from the reference queue without blocking ForkJoinPool CPU threads.-
Nested classes/interfaces inherited from interface org.postgresql.util.LazyCleaner
LazyCleaner.Cleanable<T extends java.lang.Throwable>, LazyCleaner.CleaningAction<T extends java.lang.Throwable>
-
-
Field Summary
Fields Modifier and Type Field Description private LazyCleanerImpl.Node<?>firstprivate static LazyCleanerImplinstanceprivate static java.util.logging.LoggerLOGGERprivate java.lang.ref.ReferenceQueue<java.lang.Object>queueprivate java.lang.StringthreadNameprivate booleanthreadRunningprivate java.time.DurationthreadTtl
-
Constructor Summary
Constructors Constructor Description LazyCleanerImpl(java.lang.String threadName, java.time.Duration threadTtl)Creates a LazyCleaner with the specified configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private <T extends java.lang.Throwable>
LazyCleanerImpl.Node<T>add(LazyCleanerImpl.Node<T> node)private booleancheckEmpty()static LazyCleanerImplgetInstance()Returns a default cleaner instance.booleanisThreadRunning()Returns whether the cleanup thread is currently running.<T extends java.lang.Throwable>
LazyCleaner.Cleanable<T>register(java.lang.Object obj, LazyCleaner.CleaningAction<T> action)Registers an object for cleanup when it becomes phantom reachable.private booleanremove(LazyCleanerImpl.Node<?> node)private booleanstartThread()
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
instance
private static final LazyCleanerImpl instance
-
queue
private final java.lang.ref.ReferenceQueue<java.lang.Object> queue
-
threadName
private final java.lang.String threadName
-
threadTtl
private final java.time.Duration threadTtl
-
threadRunning
private boolean threadRunning
-
first
private LazyCleanerImpl.Node<?> first
-
-
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 threadthreadTtl- 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: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
-
checkEmpty
private boolean checkEmpty()
-
add
private <T extends java.lang.Throwable> LazyCleanerImpl.Node<T> add(LazyCleanerImpl.Node<T> node)
-
startThread
private boolean startThread()
-
remove
private boolean remove(LazyCleanerImpl.Node<?> node)
-
-