I have the following situation (running on JBoss AS6 and AS7):
SomethingChangedEvent
Consider the following examples:
@Singleton
public final class Scheduler {
@Inject
private Event<SomethingChangedEvent> event;
@Schedule
private void scheduleSomething() {
event.fire(new SomethingChangedEvent());
}
}
I would expect this event to be added to some kind of queue on the server and distributed by it. Any methods that observe this kind of event by using @Observers
will be notified. The event.fire()
method will return immediately.
However, I face the following problem: Sometimes, the event.fire()
method takes like two or three minutes to return, causing havoc in my schedule since it is assumed to be invoked once every ten seconds.
So the questions are: How is this possible? What happens to events that are fired, but no one observes them? Is there a queue that can overflow?
Regards, Sven
CDI event processing occurs synchronously. There is actually a proposal to include an asynchronous processing model into the spec, but it is still being voted on. In the meantime there are two ways 'forcing' asynchronous processing:
Applying second method to your code example:
@Singleton
public final class Scheduler {
@Inject
private Event<SomethingChangedEvent> event;
@Asynchronous
private void scheduleSomething() {
event.fire(new SomethingChangedEvent());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With