简体   繁体   English

番石榴事件总线内存限制

[英]Guava eventbus memory limit

I implemented a singleton EventBus with one subscriber. 我实现了一个订阅者的单例EventBus My application has many producer (any request can be a producer). 我的应用程序有很多生产者(任何请求都可以是生产者)。

@Bean
public EventBus eventBus() {
    EventBus eventBus = new EventBus();
    eventBus.register(new MyEventHandler());
    return eventBus;
}

I could not find how to set a limit on number of events for the EventBus (how to set a memory limit for the EventBus ) and also what happens if the number of produced events is greater than EventBus capacity. 我怎么也找不到设置限制对事件的数量EventBus (如何设置内存限制的EventBus ),还生产,如果事件的数量大于发生了什么EventBus能力。

I would like EventBus to throw an exception to log the failure. 我希望EventBus引发异常以记录故障。

No need to set a memory limit. 无需设置内存限制。 It's safe, because EventBus works stateless . 这很安全,因为EventBus可以无状态运行

In a single thread, the EventBus cleans up the event-queue every time once EventBus.post() completes, so it's safe in a single thread. 在单个线程中, EventBus.post()完成后, EventBus.post()每次EventBus清除事件队列,因此在单个线程中是安全的。

In multiple-thread, EventBus uses independent event-queue for each thread. 在多线程中, EventBus为每个线程使用独立的事件队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM