Class ThreadLib


  • public class ThreadLib
    extends java.lang.Object
    Misc class
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadLib()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void async​(java.lang.Runnable r)
      Run asynchronously on another thread; the thread has started when this function returns.
      static <V> V callWithAfter​(java.util.function.Supplier<V> action, java.lang.Runnable after)
      Execute and return a value; always call the "after" runnable
      static <V> V callWithBeforeAfter​(java.util.function.Supplier<V> action, java.lang.Runnable before, java.lang.Runnable after)
      Execute.
      static <V> V callWithLock​(java.util.concurrent.locks.Lock lock, java.util.function.Supplier<V> r)
      Run inside a Lock
      static <T> T syncCallThread​(java.util.function.Supplier<T> r)
      Run synchronously but on another thread.
      static void syncOtherThread​(java.lang.Runnable r)
      Run synchronously but on another thread.
      static void withAfter​(java.lang.Runnable action, java.lang.Runnable after)
      Execute; always call the "after" runnable
      static void withBeforeAfter​(java.lang.Runnable action, java.lang.Runnable before, java.lang.Runnable after)
      Execute.
      static void withLock​(java.util.concurrent.locks.Lock lock, java.lang.Runnable r)
      Run inside a Lock
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThreadLib

        public ThreadLib()
    • Method Detail

      • async

        public static void async​(java.lang.Runnable r)
        Run asynchronously on another thread; the thread has started when this function returns.
      • syncOtherThread

        public static void syncOtherThread​(java.lang.Runnable r)
        Run synchronously but on another thread.
      • syncCallThread

        public static <T> T syncCallThread​(java.util.function.Supplier<T> r)
        Run synchronously but on another thread.
      • withBeforeAfter

        public static void withBeforeAfter​(java.lang.Runnable action,
                                           java.lang.Runnable before,
                                           java.lang.Runnable after)
        Execute. Perform the "before" action, then main action. Always call the "after" runnable if the "before" succeeded. Be careful about argument order.
        Parameters:
        action -
        before -
        after -
      • callWithBeforeAfter

        public static <V> V callWithBeforeAfter​(java.util.function.Supplier<V> action,
                                                java.lang.Runnable before,
                                                java.lang.Runnable after)
        Execute. Perform the "before" action, then main action. Always call the "after" runnable if the "before" succeeded. Be careful about argument order.
        Parameters:
        action -
        before -
        after -
      • withAfter

        public static void withAfter​(java.lang.Runnable action,
                                     java.lang.Runnable after)
        Execute; always call the "after" runnable
      • callWithAfter

        public static <V> V callWithAfter​(java.util.function.Supplier<V> action,
                                          java.lang.Runnable after)
        Execute and return a value; always call the "after" runnable
      • callWithLock

        public static <V> V callWithLock​(java.util.concurrent.locks.Lock lock,
                                         java.util.function.Supplier<V> r)
        Run inside a Lock
      • withLock

        public static void withLock​(java.util.concurrent.locks.Lock lock,
                                    java.lang.Runnable r)
        Run inside a Lock