如何在java中创建完整的未来
在Java中构建完整的未来的最佳方法是什么?我已经在下面实现了我自己的,但希望这样的东西已经存在。CompletedFuture
public class CompletedFuture<T> implements Future<T> {
private final T result;
public CompletedFuture(final T result) {
this.result = result;
}
@Override
public boolean cancel(final boolean b) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public T get() throws InterruptedException, ExecutionException {
return this.result;
}
@Override
public T get(final long l, final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
return get();
}
}