Future接口,顧名思義標的一個任務的未來:要么執行完成要么被取消
方法說明:
1.boolean cancel(boolean mayInterruptIfRunning);
Attempts to cancel execution of this task. This attempt will
fail if the task has already completed, has already been cancelled,
or could not be cancelled for some other reason
取消執行任務。如果任務已經執行完成,或者已經取消,或者由于其他原因不能被取消,則取消失敗
通過參數設置是否打斷任務的執行
2.boolean isCancelled();
if this task was cancelled before it completed normally
查看正常結束之前是否被取消
3.boolean isDone();
if this task completed
查看任務是否已結束
4.V get() throws InterruptedException, ExecutionException;
Waits if necessary for the computation to complete, and then
retrieves its result
等到任務執行結束(如需要等待),然后返回結果
5.V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException;
Waits if necessary for at most the given time for the computation
to complete, and then retrieves its result, if available.
在指定的等待時間內讓任務執行(如需要等待),如果有結果就返回
2.Future<V>
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
推薦閱讀更多精彩內容
- Android Handler機制系列文章整體內容如下: Android Handler機制1之ThreadAnd...