Class Disposer
java.lang.Object
ch.raffael.meldioc.util.concurrent.Disposer
public class Disposer
extends java.lang.Object
A simple utility that helps to thread-safely dispose lazy things.
General usage:
- call
onDispose()to add hook to be run when disposing things - call
dispose()to run all added hooks and remove them
onDispose() and dispose() synchronize on a lock that may be
passed to the constructor. By default, this Disposer instance will be used
for locking.-
Constructor Summary
-
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Disposer
public Disposer() -
Disposer
public Disposer(@Nullable java.lang.Object lock)
-
-
Method Details
-
onDispose
public <T> T onDispose(T instance, java.lang.Runnable onDispose) -
onDispose
public <T> T onDispose(T instance, java.util.function.Consumer<? super T> onDispose) -
onDispose
public void onDispose(java.lang.Runnable onDispose) -
dispose
public void dispose() -
lock
public java.lang.Object lock()
-