Class Callables
java.lang.Object
com.google.common.util.concurrent.Callables
Static utility methods pertaining to the
Callable interface.- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> AsyncCallable<T> asAsyncCallable(Callable<T> callable, ListeningExecutorService listeningExecutorService) Creates anAsyncCallablefrom aCallable.static <T> Callable<T> returning(T value) Creates aCallablewhich immediately returns a preset value each time it is called.(package private) static RunnablethreadRenaming(Runnable task, Supplier<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> Callable<T> threadRenaming(Callable<T> callable, Supplier<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(String threadName, Thread currentThread) Tries to set name of the givenThread, returns true if successful.
-
Constructor Details
-
Callables
private Callables()
-
-
Method Details
-
returning
Creates aCallablewhich immediately returns a preset value each time it is called. -
asAsyncCallable
public static <T> AsyncCallable<T> asAsyncCallable(Callable<T> callable, ListeningExecutorService listeningExecutorService) Creates anAsyncCallablefrom aCallable.The
AsyncCallablereturns theListenableFutureresulting fromListeningExecutorService.submit(Callable).- Since:
- 20.0
-
threadRenaming
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
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
Tries to set name of the givenThread, returns true if successful.
-