TimeUnit.TimedWait(Object, Int64) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用這個時間單位執行定 Object#wait(long, int) Object.wait 時操作。
[Android.Runtime.Register("timedWait", "(Ljava/lang/Object;J)V", "")]
public void TimedWait(Java.Lang.Object? obj, long timeout);
[<Android.Runtime.Register("timedWait", "(Ljava/lang/Object;J)V", "")>]
member this.TimedWait : Java.Lang.Object * int64 -> unit
參數
- obj
- Object
等待的對象
- timeout
- Int64
等待時間最長。 如果小於或等於零,則完全不要等待。
- 屬性
例外狀況
等待時被打斷
備註
使用這個時間單位執行定 Object#wait(long, int) Object.wait 時操作。 這是一種方便方法,將逾時參數轉換為方法所需的 Object.wait 形式。
例如,你可以實作一種阻擋 poll 方法(參見 BlockingQueue#poll(long, TimeUnit) BlockingQueue.poll),使用:
{@code
public E poll(long timeout, TimeUnit unit)
throws InterruptedException {
synchronized (lock) {
while (isEmpty()) {
unit.timedWait(lock, timeout);
...
}
}
}}
的 java.util.concurrent.TimeUnit.timedWait(java.lang.Object, long)Java 檔。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。