Class LeakDetect
- java.lang.Object
-
- com.linkedin.alpini.base.misc.LeakDetect
-
public final class LeakDetect extends java.lang.Object
General purpose object reference leak detector with recovery.A reference to the phantom must still be maintained somewhere... For example:
private final AtomicReference<PhantomReference<AsyncFutureListener<?>>> _phantom = new AtomicReference<>();
Then using the LeakDetect tool is as simple as:
PhantomReference<AsyncFutureListener<?>> phantom = LeakDetect .newReference(responseListener, () -> ctx.executor().execute(() -> promise.setSuccess(internalBuildErrorResponse(request, new IllegalStateException("Reference lost"))))); promise.addListener(future -> { phantom.clear(); _phantom.compareAndSet(phantom, null); }); _phantom.lazySet(phantom);
Note that the recovery should not reference any object which may hold a reference to the object which is being monitored for leaks.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> java.lang.ref.PhantomReference<T>
newReference(T object, java.lang.Runnable recover)
Make a phantom reference for leak detection.
-
-
-
Method Detail
-
newReference
public static <T> java.lang.ref.PhantomReference<T> newReference(T object, java.lang.Runnable recover)
Make a phantom reference for leak detection. Be sure to callReference.clear()
when the object is no longer considered leaked.- Parameters:
object
- Object to monitor.recover
- Task to invoke when a leak occurs.- Returns:
- Phantom reference.
-
-