mysql in jd price is 109.90 mysql in dangdang price is 110.09 mysql in taobao price is 109.20 **********costTime: 3108 ms
[优化性能]
1 2 3 4 5 6 7 8 9 10
mysql in jd price is 109.23 mysql in dangdang price is 109.66 mysql in taobao price is 109.11 **********costTime1: 3081 ms
**************************** mysql in jd price is 110.37 mysql in dangdang price is 110.25 mysql in taobao price is 109.79 **********costTime2: 1008 ms
// Waits if necessary for this future to complete, and then returns its result. public T get()throws InterruptedException, ExecutionException { Object r; return reportGet((r = result) == null ? waitingGet(true) : r); }
// Waits if necessary for at most the given time for this future to complete, and then returns its result, if available. public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { Object r; longnanos= unit.toNanos(timeout); return reportGet((r = result) == null ? timedGet(nanos) : r); }
// Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. To better conform with the use of common functional forms, if a computation involved in the completion of this CompletableFuture threw an exception, this method throws an (unchecked) {@link CompletionException} with the underlying exception as its cause. public T join() { Object r; return reportJoin((r = result) == null ? waitingGet(false) : r); }
// Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent. public T getNow(T valueIfAbsent) { Object r; return ((r = result) == null) ? valueIfAbsent : reportJoin(r); }
主动触发计算
方法
说明//
public boolean complete(T value)
是否打断get方法,立即返回value
1 2 3 4 5 6
// If not already completed, sets the value returned by {@link#get()} and related methods to the given value. publicbooleancomplete(T value) { booleantriggered= completeValue(value); postComplete(); return triggered; }
// Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function. public <U> CompletableFuture<U> thenApply( Function<? super T,? extends U> fn) { return uniApplyStage(null, fn); }
// Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed with this stage's result and exception as arguments to the supplied function. // When this stage is complete, the given function is invoked with the result (or {@code null} if none) and the exception (or{@code null} if none) of this stage as arguments, and the function's result is used to complete the returned stage. public <U> CompletableFuture<U> handle( BiFunction<? super T, Throwable, ? extends U> fn) { return uniHandleStage(null, fn); }
对计算结果进行消费
接收任务的处理结果,并消费处理,无返回结果
thenAccept
方法
说明
public CompletableFuture<Void> thenAccept(Consumer<? super T> action)
// Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action. public CompletableFuture<Void> thenAccept(Consumer<? super T> action) { return uniAcceptStage(null, action); }
// Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function. public <U> CompletableFuture<U> applyToEither( CompletionStage<? extends T> other, Function<? super T, U> fn) { return orApplyStage(null, other, fn); }
// Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function. public <U,V> CompletableFuture<V> thenCombine( CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn) { return biApplyStage(null, other, fn); }