Class Disposer

java.lang.Object
ch.raffael.meldioc.util.concurrent.Disposer

public class Disposer extends 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
Both 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 Details

    • Disposer

      public Disposer()
    • Disposer

      public Disposer(@Nullable @Nullable Object lock)
  • Method Details

    • onDispose

      public <T> T onDispose(T instance, Runnable onDispose)
    • onDispose

      public <T> T onDispose(T instance, Consumer<? super T> onDispose)
    • onDispose

      public void onDispose(Runnable onDispose)
    • dispose

      public void dispose()
    • lock

      public Object lock()