Events not firing in Listeners in multi-thread environment
Issue
When you start 5 threads that call createNotification, thereby firing 5 CreateEvents, only the first event is sent to the createNotification method in ListenerImpl.
The other 4 events are, as far as we can see, silently dropped.
Is this correct behaviour? We expected the other 4 events to be queued internally by JBoss and handled sequentially by ListenerImpl.
@Stateless
public class Notifier {
@Inject
Event<AppointmentCreatedEvent> aftaleCreatedListeners;
public void createNotification(Appointment data) {
aftaleCreatedListeners.fire(new CreateEvents(data));
}
}
public interface Listener {
@Asynchronous
public void createNotification(@Observes(during = TransactionPhase.AFTER_SUCCESS) Appointment event);
}
@Singleton
public class ListenerImpl implements Listener {
private static Logger logger = CapLog.getCategory(ListenerImpl.class);
@Override
@Asynchronous
public void createNotification(@Observes(during = TransactionPhase.AFTER_SUCCESS) Appointment event) {
logger.debug("ListenerImpl Event triggered, Oid=" + event.getNew().getAppointmentId().serialize());
try {
Thread.sleep(60*1000);
} catch (Exception e) {
}
}
}
In order to ensure that all 5 events are handled, we have added the following annotation to the createNotification method in ListenerImpl: @Lock(LockType.READ)
Environment
- Red Hat JBoss Enterprise Application Platform 6.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.