FIFO オブザーバー/オブザーバブル デカップリング キューを実装しようとしていますが、キューが空でなくなるまでメソッドを待機させてから返す方法がわかりません。これが私の現在の試みですが、もっとエレガントな解決策が必要だと確信しています。
/*
* Waits until there is data, then returns it.
*/
private Double[] get() {
while (queue.isEmpty()) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// Don't care.
}
}
return queue.removeFirst();
}