2014-08-27 93 views
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")); 

@EDIT

以下測試證實,接收器守護線程可以處理事件之前退出。

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) { 
} 

回答

3

如果這是你的程序的程度並沒有什麼,以防止系統退出,直到事件被處理,然後通知你不會有時間,系統簡單地退出之前完成。

您需要一個CountDownLatchThread.sleep(1000)以允許系統時間將事件從一個線程傳播到另一個線程。