public class DefaultFuture<V> extends AbstractFuture<V> implements Callable<V>, Runnable
| 构造器和说明 |
|---|
DefaultFuture(Callable task) |
DefaultFuture(Runnable task) |
| 限定符和类型 | 方法和说明 |
|---|---|
GenericFuture<V> |
addListener(GenericFutureListener<? extends GenericFuture<? super V>> listener)
Adds the specified listener to this future.
|
GenericFuture<V> |
addListeners(GenericFutureListener<? extends GenericFuture<? super V>>... listeners)
Adds the specified listeners to this future.
|
GenericFuture<V> |
await()
一直等,直到 完成,或者中断
|
boolean |
await(long timeoutMillis)
Waits for this future to be completed within the
specified time limit.
|
boolean |
await(long timeout,
TimeUnit unit)
Waits for this future to be completed within the
specified time limit.
|
GenericFuture<V> |
awaitUninterruptibly()
Waits for this future to be completed without
interruption.
|
boolean |
awaitUninterruptibly(long timeoutMillis)
Waits for this future to be completed within the
specified time limit without interruption.
|
boolean |
awaitUninterruptibly(long timeout,
TimeUnit unit)
Waits for this future to be completed within the
specified time limit without interruption.
|
V |
call() |
boolean |
cancel(boolean mayInterruptIfRunning)
If the cancellation was successful it will fail the future with a
CancellationException. |
Throwable |
cause()
Returns the cause of the failed I/O operation if the I/O operation has
failed.
|
V |
getNow()
Return the result without blocking.
|
boolean |
isCancellable()
returns
true if and only if the operation can be cancelled via GenericFuture.cancel(boolean). |
boolean |
isCancelled() |
boolean |
isSuccess()
Returns
true if and only if the I/O operation was completed
successfully. |
GenericFuture<V> |
removeListener(GenericFutureListener<? extends GenericFuture<? super V>> listener)
Removes the first occurrence of the specified listener from this future.
|
GenericFuture<V> |
removeListeners(GenericFutureListener<? extends GenericFuture<? super V>>... listeners)
Removes the first occurrence for each of the listeners from this future.
|
void |
run() |
void |
setCancelable(boolean cancelable) |
void |
setExpectedResult(V expectedResult) |
static <V> GenericFuture<V> |
submit(ExecutorService executorService,
Callable<V> callable) |
static <V> GenericFuture<V> |
submit(ExecutorService executorService,
Callable<V> callable,
boolean cancelable) |
static <V> GenericFuture<V> |
submit(ExecutorService executorService,
Runnable runnable) |
static <V> GenericFuture<V> |
submit(ExecutorService executorService,
Runnable runnable,
boolean cancelable) |
static <V> GenericFuture<V> |
submit(ExecutorService executorService,
Runnable runnable,
boolean cancelable,
V result) |
GenericFuture<V> |
sync()
Waits for this future until it is done, and rethrows the cause of the failure if this future
failed.
|
GenericFuture<V> |
syncUninterruptibly()
Waits for this future until it is done, and rethrows the cause of the failure if this future
failed.
|
void |
with(Future<V> future) |
get, get, isDonepublic DefaultFuture(Callable task)
public DefaultFuture(Runnable task)
public void setCancelable(boolean cancelable)
public GenericFuture<V> addListener(GenericFutureListener<? extends GenericFuture<? super V>> listener)
GenericFutureaddListener 在接口中 GenericFuture<V>public GenericFuture<V> addListeners(GenericFutureListener<? extends GenericFuture<? super V>>... listeners)
GenericFutureaddListeners 在接口中 GenericFuture<V>public GenericFuture<V> removeListener(GenericFutureListener<? extends GenericFuture<? super V>> listener)
GenericFutureremoveListener 在接口中 GenericFuture<V>public GenericFuture<V> removeListeners(GenericFutureListener<? extends GenericFuture<? super V>>... listeners)
GenericFutureremoveListeners 在接口中 GenericFuture<V>public GenericFuture<V> sync() throws InterruptedException
GenericFuturesync 在接口中 GenericFuture<V>InterruptedExceptionpublic GenericFuture<V> syncUninterruptibly()
GenericFuturesyncUninterruptibly 在接口中 GenericFuture<V>public GenericFuture<V> await() throws InterruptedException
await 在接口中 GenericFuture<V>InterruptedException - if the current thread was interruptedpublic boolean await(long timeout,
TimeUnit unit)
throws InterruptedException
GenericFutureawait 在接口中 GenericFuture<V>true if and only if the future was completed within
the specified time limitInterruptedException - if the current thread was interruptedpublic boolean await(long timeoutMillis)
throws InterruptedException
GenericFutureawait 在接口中 GenericFuture<V>true if and only if the future was completed within
the specified time limitInterruptedException - if the current thread was interruptedpublic GenericFuture<V> awaitUninterruptibly()
GenericFutureInterruptedException and
discards it silently.
一直等,直到完成。中断后也继续awaitUninterruptibly 在接口中 GenericFuture<V>public boolean awaitUninterruptibly(long timeout,
TimeUnit unit)
GenericFutureInterruptedException and discards it silently.
在特定的时间内一直等,结束条件是: 时间到,完成
出现中断,也继续awaitUninterruptibly 在接口中 GenericFuture<V>true if and only if the future was completed within
the specified time limitpublic boolean awaitUninterruptibly(long timeoutMillis)
GenericFutureInterruptedException and discards it silently.awaitUninterruptibly 在接口中 GenericFuture<V>true if and only if the future was completed within
the specified time limitpublic boolean cancel(boolean mayInterruptIfRunning)
GenericFutureCancellationException.public V getNow()
GenericFuturenull.
As it is possible that a null value is used to mark the future as successful you also need to check
if the future is really done with Future.isDone() and not rely on the returned null value.getNow 在接口中 GenericFuture<V>public boolean isCancelled()
isCancelled 在接口中 Future<V>public boolean isSuccess()
GenericFuturetrue if and only if the I/O operation was completed
successfully.isSuccess 在接口中 GenericFuture<V>public boolean isCancellable()
GenericFuturetrue if and only if the operation can be cancelled via GenericFuture.cancel(boolean).isCancellable 在接口中 GenericFuture<V>public Throwable cause()
GenericFuturecause 在接口中 GenericFuture<V>null if succeeded or this future is not
completed yet.public void setExpectedResult(V expectedResult)
public static <V> GenericFuture<V> submit(ExecutorService executorService, Runnable runnable, boolean cancelable, V result)
public static <V> GenericFuture<V> submit(ExecutorService executorService, Runnable runnable)
public static <V> GenericFuture<V> submit(ExecutorService executorService, Runnable runnable, boolean cancelable)
public static <V> GenericFuture<V> submit(ExecutorService executorService, Callable<V> callable)
public static <V> GenericFuture<V> submit(ExecutorService executorService, Callable<V> callable, boolean cancelable)
Copyright © 2022. All rights reserved.