0

以下でreactor-core 1.1.4-RELEASE試しましたが、何も印刷されませんでした。何を見逃したはずですか?

Reactor reactor = Reactors.reactor(new Environment());
reactor.on(
        $("hello"),
        (Event<String> ev) -> System.out.println("hello "
                + ev.getData()));
reactor.notify("hello", Event.wrap("world"));

@編集

以下のテストでは、受信側のデーモン スレッドがイベントを処理する前に終了できることを確認します。

Reactor reactor = Reactors.reactor(new Environment());
reactor.on($("hello"), (Event<String> ev) -> {
    System.out.println(Thread.currentThread().getName());
    System.out.println(Thread.currentThread().isDaemon());
    System.out.println("hello " + ev.getData());
});
reactor.notify("hello", Event.wrap("world"));
try {
    Thread.sleep(1000);
} catch (Exception e) {
}
4

1 に答える 1

3

これがプログラムの範囲であり、イベントが処理されるまでシステムの終了を妨げるものがない場合、システムが単に終了する前に通知が完了する時間がありません。

システム時間が 1 つのスレッドから別のスレッドにイベントを伝搬できるようにするには、CountDownLatchまたはが必要です。Thread.sleep(1000)

于 2014-08-27T20:11:03.567 に答える