私は、エンド ユーザー スクリプトが完了オブジェクトの論理的な組み合わせを待機できるように、非同期計算用の完了オブジェクトを含むスクリプト可能なオブジェクト モデルに取り組んでいます。問題は、組み込みの監視オブジェクトを経由して使用するwait()
と、notify()
複数のオブジェクトを待機するメカニズムがないことです。複数のオブジェクトを構成する方法が不明です。notifyAll()
CountDownLatch
私はこのようなものが欲しい:
/** object representing the state of completion of an operation
* which is initially false, then becomes true when the operation completes */
interface Completion
{
/** returns whether the operation is complete */
public boolean isDone();
/** waits until the operation is complete */
public void await() throws InterruptedException;
}
class SomeObject
{
public Completion startLengthyOperation() { ... }
}
class Completions
{
public Completion or(Completion ...objects);
public Completion and(Completion ...objects);
}
スクリプトまたはエンドアプリケーションがこれを実行できるように:
SomeObject obj1, obj2, obj3;
... /* assign obj1,2,3 */
Completion c1 = obj1.startLengthOperation();
Completion c2 = obj2.startLengthOperation();
Completion c3 = obj3.startLengthOperation();
Completion anyOf = Completions.or(c1,c2,c3);
Completion allOf = Completions.and(c1,c2,c3);
anyOf.await(); // wait for any of the 3 to be finished
... // do something
allOf.await(); // wait for all of the 3 to be finished
... // do something else
using を実装すれば、このand()
ケースは簡単に処理CountDownLatch
できます。任意の順序でそれらすべてを待つだけです。しかし、どうすればor()
ケースを処理できますか?