Future.get()在任务完成后多次调用Java时,Java的行为如何?它会返回相同的结果吗?或者,ExecutionException如果计算失败,会一次又一次地抛出相同的异常吗?我在文档中找不到任何关于它的东西!
Jes*_*per 31
你可以叫get()上Future经常只要你喜欢,如果产生结果的任务还没有完成它只会阻止.
如果任务已经完成,它将立即返回任务的结果.
如果任务因异常而失败,get()则ExecutionException每次调用时都会调用.
我在文档中找不到任何有关它的内容!
你读过它们吗?因为当我读到它们时,我得到了答案,这就是......
Run Code Online (Sandbox Code Playgroud)V get() throws InterruptedException, ExecutionException如有必要,等待计算完成,然后检索 其结果。
Run Code Online (Sandbox Code Playgroud)Returns: the computed result Throws: CancellationException - if the computation was cancelled ExecutionException - if the computation threw an exception InterruptedException - if the current thread was interrupted while waiting
如果计算未完成,它将等待,如果计算已经完成,它将尽快返回结果,无论调用多少次
| 归档时间: |
|
| 查看次数: |
6448 次 |
| 最近记录: |