CheckedFuture cannot properly support the chained operations that are the
primary goal of
CheckedFuture also encourages users to
rethrow exceptions from one thread in another thread, producing misleading stack traces.
Additionally, it has a surprising policy about which exceptions to map and which to leave
untouched. Guava users who want a
CheckedFuture can fork the classes for their own
use, possibly specializing them to the particular exception type they use. We recommend that
most people use
ListenableFuture and perform any exception wrapping themselves. This
class is scheduled for removal from Guava in January 2019.
@Beta @CanIgnoreReturnValue @Deprecated @GwtCompatible public interface CheckedFuture<V,X extends Exception> extends ListenableFuture<V>
CheckedFuture is a
ListenableFuture that includes versions of the
methods that can throw a checked exception. This makes it easier to create a future that executes
logic which can throw an exception.
Warning: We recommend against using
CheckedFuture in new projects.
CheckedFuture is difficult to build libraries atop.
CheckedFuture ports of methods like
Futures.transformAsync(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.util.concurrent.AsyncFunction<? super I, ? extends O>, java.util.concurrent.Executor) have historically had bugs, and some of these bugs are necessary,
unavoidable consequences of the
CheckedFuture API. Additionally,
encourages users to take exceptions from one thread and rethrow them in another, producing
confusing stack traces.
A common implementation is
This interface also extends the ListenableFuture interface to allow listeners to be added.
This allows the future to be used as a normal
Future or as an asynchronous callback
mechanism as needed. This allows multiple callbacks to be registered for a particular task, and
the future will guarantee execution of all listeners when the task completes.
For a simpler alternative to CheckedFuture, consider accessing Future values with
|Modifier and Type
|Method and Description
V checkedGet() throws X extends Exception
Future.get() that will translate
V checkedGet(long timeout, TimeUnit unit) throws TimeoutException, X extends Exception
Future.get(long, TimeUnit) that will translate
application-specific exceptions. On timeout this method throws a normal
Copyright © 2010–2019. All rights reserved.