Class JdkFutureAdapters
- java.lang.Object
-
- com.google.common.util.concurrent.JdkFutureAdapters
-
@GwtIncompatible public final class JdkFutureAdapters extends java.lang.Object
Utilities necessary for working with libraries that supply plainFutureinstances. Note that, whenever possible, it is strongly preferred to modify those libraries to returnListenableFuturedirectly.For interoperability between
ListenableFutureandCompletableFuture, consider Future Converter.- Since:
- 10.0 (replacing
Futures.makeListenable, which existed in 1.0) - Author:
- Sven Mawson
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V extends @Nullable java.lang.Object>
ListenableFuture<V>listenInPoolThread(java.util.concurrent.Future<V> future)Assigns a thread to the givenFutureto provideListenableFuturefunctionality.static <V extends @Nullable java.lang.Object>
ListenableFuture<V>listenInPoolThread(java.util.concurrent.Future<V> future, java.util.concurrent.Executor executor)Submits a blocking task for the givenFutureto provideListenableFuturefunctionality.
-
-
-
Method Detail
-
listenInPoolThread
public static <V extends @Nullable java.lang.Object> ListenableFuture<V> listenInPoolThread(java.util.concurrent.Future<V> future)
Assigns a thread to the givenFutureto provideListenableFuturefunctionality.Warning: If the input future does not already implement
ListenableFuture, the returned future will emulateListenableFuture.addListener(java.lang.Runnable, java.util.concurrent.Executor)by taking a thread from an internal, unbounded pool at the first call toaddListenerand holding it until the future is done.Prefer to create
ListenableFutureinstances withSettableFuture,MoreExecutors.listeningDecorator( java.util.concurrent.ExecutorService),ListenableFutureTask,AbstractFuture, and other utilities over creating plainFutureinstances to be upgraded toListenableFutureafter the fact.
-
listenInPoolThread
public static <V extends @Nullable java.lang.Object> ListenableFuture<V> listenInPoolThread(java.util.concurrent.Future<V> future, java.util.concurrent.Executor executor)
Submits a blocking task for the givenFutureto provideListenableFuturefunctionality.Warning: If the input future does not already implement
ListenableFuture, the returned future will emulateListenableFuture.addListener(java.lang.Runnable, java.util.concurrent.Executor)by submitting a task to the given executor at the first call toaddListener. The task must be started by the executor promptly, or else the returnedListenableFuturemay fail to work. The task's execution consists of blocking until the input future is done, so each call to this method may claim and hold a thread for an arbitrary length of time. Use of bounded executors or other executors that may fail to execute a task promptly may result in deadlocks.Prefer to create
ListenableFutureinstances withSettableFuture,MoreExecutors.listeningDecorator( java.util.concurrent.ExecutorService),ListenableFutureTask,AbstractFuture, and other utilities over creating plainFutureinstances to be upgraded toListenableFutureafter the fact.- Since:
- 12.0
-
-