Class Callables
- java.lang.Object
-
- com.google.common.util.concurrent.Callables
-
@GwtCompatible(emulated=true) public final class Callables extends java.lang.Object
Static utility methods pertaining to theCallableinterface.- Since:
- 1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description privateCallables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> AsyncCallable<T>asAsyncCallable(java.util.concurrent.Callable<T> callable, ListeningExecutorService listeningExecutorService)Creates anAsyncCallablefrom aCallable.static <T> java.util.concurrent.Callable<T>returning(T value)Creates aCallablewhich immediately returns a preset value each time it is called.(package private) static java.lang.RunnablethreadRenaming(java.lang.Runnable task, Supplier<java.lang.String> nameSupplier)Wraps the given runnable such that for the duration ofRunnable.run()the thread that is running with have the given name.(package private) static <T> java.util.concurrent.Callable<T>threadRenaming(java.util.concurrent.Callable<T> callable, Supplier<java.lang.String> nameSupplier)Wraps the given callable such that for the duration ofCallable.call()the thread that is running will have the given name.private static booleantrySetName(java.lang.String threadName, java.lang.Thread currentThread)Tries to set name of the givenThread, returns true if successful.
-
-
-
Method Detail
-
returning
public static <T> java.util.concurrent.Callable<T> returning(T value)
Creates aCallablewhich immediately returns a preset value each time it is called.
-
asAsyncCallable
@Beta @GwtIncompatible public static <T> AsyncCallable<T> asAsyncCallable(java.util.concurrent.Callable<T> callable, ListeningExecutorService listeningExecutorService)
Creates anAsyncCallablefrom aCallable.The
AsyncCallablereturns theListenableFutureresulting fromListeningExecutorService.submit(Callable).- Since:
- 20.0
-
threadRenaming
@GwtIncompatible static <T> java.util.concurrent.Callable<T> threadRenaming(java.util.concurrent.Callable<T> callable, Supplier<java.lang.String> nameSupplier)
Wraps the given callable such that for the duration ofCallable.call()the thread that is running will have the given name.- Parameters:
callable- The callable to wrapnameSupplier- The supplier of thread names,getwill be called once for each invocation of the wrapped callable.
-
threadRenaming
@GwtIncompatible static java.lang.Runnable threadRenaming(java.lang.Runnable task, Supplier<java.lang.String> nameSupplier)
Wraps the given runnable such that for the duration ofRunnable.run()the thread that is running with have the given name.- Parameters:
task- The Runnable to wrapnameSupplier- The supplier of thread names,getwill be called once for each invocation of the wrapped callable.
-
trySetName
@GwtIncompatible private static boolean trySetName(java.lang.String threadName, java.lang.Thread currentThread)
Tries to set name of the givenThread, returns true if successful.
-
-