public class Event { @Subscribe public void sub(String message) { System.out.println(message); }}
消息发起方:
public void testEventBus() { //同步 EventBus eventBus = new EventBus(); //异步 //AsyncEventBus eventBus = new AsyncEventBus(Executors.newFixedThreadPool(3)); eventBus.register(new Event());//注册事件 eventBus.post("ssdf");// 触发事件处理 }
ps:
com.google.common.eventbus.EventBus$LoggingSubscriberExceptionHandler.handleException Could not dispatch event: XXX这个错误可能是由于lister中@Subscribe对应方法抛出了异常。