@ThreadSafe public class SettableFuture<T> extends Object implements Future<T>
SettableFuture is a
Future implementation where the responsibility
for producing the result is external to the future instance, unlike
FutureTask where the future holds the operation
(a Callable or Runnable
instance) and the first thread that calls
FutureTask.run() executes the operation.
This is useful in situations where all the inputs may not be available at construction time.
| Constructor and Description |
|---|
SettableFuture() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
T |
get()
Get the value of the future.
|
T |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
SettableFuture<T> |
set(T value)
Set the value returned by
get() and get(long, TimeUnit) |
SettableFuture<T> |
setException(Throwable throwable)
Set the exception thrown as the causal exception of an ExecutionException
by
get() and get(long, TimeUnit) |
public final SettableFuture<T> set(T value)
get() and get(long, TimeUnit)
Note that this can only be done once unless the value of the second set equals the first value otherwise an exception will be thrown. It also cannot be set if this future has been cancelled or an exception has been set.
value - the value to be set.SettableFuture object.public final SettableFuture<T> setException(Throwable throwable)
get() and get(long, TimeUnit)
Note that this can only be done once unless the value of the second
setException(Throwable) equals the first value otherwise an
exception will be thrown (as most exceptions do not implement equals this
effectively means the same reference). It also cannot be set if this future
has been cancelled or a a value has been set.
throwable - a Throwable.SettableFuture.public final T get() throws InterruptedException, ExecutionException
get in interface Future<T>InterruptedException - if any.ExecutionException - if any.public final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<T>InterruptedExceptionExecutionExceptionTimeoutExceptionpublic final boolean isCancelled()
isCancelled in interface Future<T>Copyright © 2016 Atlassian. All rights reserved.