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 anAsyncCallable
from aCallable
.static <T> Callable
<T> returning
(T value) Creates aCallable
which immediately returns a preset value each time it is called.(package private) static Runnable
threadRenaming
(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 boolean
trySetName
(String threadName, Thread currentThread) Tries to set name of the givenThread
, returns true if successful.
-
Constructor Details
-
Callables
private Callables()
-
-
Method Details
-
returning
Creates aCallable
which immediately returns a preset value each time it is called. -
asAsyncCallable
public static <T> AsyncCallable<T> asAsyncCallable(Callable<T> callable, ListeningExecutorService listeningExecutorService) Creates anAsyncCallable
from aCallable
.The
AsyncCallable
returns theListenableFuture
resulting 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,get
will 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,get
will be called once for each invocation of the wrapped callable.
-
trySetName
Tries to set name of the givenThread
, returns true if successful.
-