Class LeakDetector
java.lang.Object
cloud.opencode.base.classloader.leak.LeakDetector
Global singleton detector for ClassLoader memory leaks
ClassLoader 内存泄漏的全局单例检测器
Uses PhantomReference and a ReferenceQueue to detect ClassLoader
instances that are garbage-collected without being explicitly closed (untracked).
A virtual-thread daemon continuously polls the reference queue and generates
LeakReport entries for any leaked ClassLoaders.
使用 PhantomReference 和 ReferenceQueue 检测未显式关闭(取消追踪)
就被垃圾回收的 ClassLoader 实例。一个虚拟线程守护进程持续轮询引用队列,
并为任何泄漏的 ClassLoader 生成 LeakReport 条目。
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-classloader V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidClear all leak reports 清除所有泄漏报告static LeakDetectorReturns the global singleton instance (lazy-initialized on first call) 返回全局单例实例(首次调用时延迟初始化)Returns the list of detected leak reports 返回已检测到的泄漏报告列表intReturns the number of currently tracked ClassLoaders 返回当前被追踪的 ClassLoader 数量voidshutdown()Shutdown the leak detector poll thread 关闭泄漏检测器轮询线程voidtrack(ClassLoader classLoader, String name, LeakDetection level) Register a ClassLoader for leak tracking 注册一个 ClassLoader 进行泄漏追踪voiduntrack(ClassLoader classLoader) Unregister a ClassLoader from leak tracking (called on close) 取消注册 ClassLoader 的泄漏追踪(在 close 时调用)
-
Method Details
-
shutdown
public void shutdown()Shutdown the leak detector poll thread 关闭泄漏检测器轮询线程Interrupts the poll thread. Primarily useful for orderly shutdown in application servers or test environments.
中断轮询线程。主要用于应用服务器或测试环境中的有序关闭。
-
getInstance
Returns the global singleton instance (lazy-initialized on first call) 返回全局单例实例(首次调用时延迟初始化)- Returns:
- the singleton LeakDetector | 单例 LeakDetector
-
track
Register a ClassLoader for leak tracking 注册一个 ClassLoader 进行泄漏追踪If the level is
LeakDetection.DISABLED, this method is a no-op.如果级别为
LeakDetection.DISABLED,此方法不执行任何操作。- Parameters:
classLoader- the ClassLoader to track | 要追踪的 ClassLoadername- a descriptive name for the ClassLoader | ClassLoader 的描述性名称level- the detection level | 检测级别- Throws:
NullPointerException- if any argument is null | 当任何参数为 null 时
-
untrack
Unregister a ClassLoader from leak tracking (called on close) 取消注册 ClassLoader 的泄漏追踪(在 close 时调用)- Parameters:
classLoader- the ClassLoader to untrack | 要取消追踪的 ClassLoader- Throws:
NullPointerException- if classLoader is null | 当 classLoader 为 null 时
-
getLeakReports
Returns the list of detected leak reports 返回已检测到的泄漏报告列表- Returns:
- unmodifiable list of leak reports | 不可修改的泄漏报告列表
-
getTrackedCount
public int getTrackedCount()Returns the number of currently tracked ClassLoaders 返回当前被追踪的 ClassLoader 数量- Returns:
- tracked count | 追踪数量
-
clearReports
public void clearReports()Clear all leak reports 清除所有泄漏报告
-