Class Callables

java.lang.Object
com.google.common.util.concurrent.Callables

public final class Callables extends Object
Static utility methods pertaining to the Callable interface.
Since:
1.0
  • Constructor Details

    • Callables

      private Callables()
  • Method Details

    • returning

      public static <T> Callable<T> returning(T value)
      Creates a Callable which immediately returns a preset value each time it is called.
    • asAsyncCallable

      public static <T> AsyncCallable<T> asAsyncCallable(Callable<T> callable, ListeningExecutorService listeningExecutorService)
      Since:
      20.0
    • threadRenaming

      static <T> Callable<T> threadRenaming(Callable<T> callable, Supplier<String> nameSupplier)
      Wraps the given callable such that for the duration of Callable.call() the thread that is running will have the given name.
      Parameters:
      callable - The callable to wrap
      nameSupplier - The supplier of thread names, get will be called once for each invocation of the wrapped callable.
    • threadRenaming

      static Runnable threadRenaming(Runnable task, Supplier<String> nameSupplier)
      Wraps the given runnable such that for the duration of Runnable.run() the thread that is running with have the given name.
      Parameters:
      task - The Runnable to wrap
      nameSupplier - The supplier of thread names, get will be called once for each invocation of the wrapped callable.
    • trySetName

      private static boolean trySetName(String threadName, Thread currentThread)
      Tries to set name of the given Thread, returns true if successful.