Java Future<V> 接口-会得到什么(长超时,TimeUnit 单位)return?
Java Future<V> interface- what will get(long timeout, TimeUnit unit) return?
文档有点混乱。方法return如果超时会怎样?文档说 "the computed result",但是如果计算超时怎么办?是否为空?
谢谢
如果计算超时,它会抛出一个java.util.concurrent.TimeoutException
来自Java docs:
Exception thrown when a blocking operation times out. Blocking
operations for which a timeout is specified need a means to indicate
that the timeout has occurred. For many such operations it is possible
to return a value that indicates timeout; when that is not possible or
desirable then TimeoutException should be declared and thrown.
文档有点混乱。方法return如果超时会怎样?文档说 "the computed result",但是如果计算超时怎么办?是否为空?
谢谢
如果计算超时,它会抛出一个java.util.concurrent.TimeoutException
来自Java docs:
Exception thrown when a blocking operation times out. Blocking operations for which a timeout is specified need a means to indicate that the timeout has occurred. For many such operations it is possible to return a value that indicates timeout; when that is not possible or desirable then TimeoutException should be declared and thrown.