[cdi-dev] What, if any, guarantees are made about invoking asynchronous event observer methods?
mkouba at redhat.com
Fri May 12 03:57:43 EDT 2017
FYI there is already https://issues.jboss.org/browse/CDI-570 which seems
to be related.
Dne 12.5.2017 v 08:39 Martin Kouba napsal(a):
> Dne 11.5.2017 v 21:30 Laird Nelson napsal(a):
>> I'm using CDI 2.0 and Weld 3.0.0.CR2 in "SE mode".
>> If I fire an asynchronous event without any special notification
>> options, my understanding is that the container will arrange for that
>> event to be delivered to asynchronous observers.
>> Is (appropriate) asynchronous observer method invocation guaranteed to
>> happen at some point? Section 10.2.2 seems to hint that it is:
>> "Event fired [sic] with the fireAsync() method is [sic] fired
>> asynchronously. *All the resolved asynchronous observers* (as defined in
>> Observer resolution) *are called* in one or more different threads."
>> To me, this says that if I use fireAsync() to fire an event, then if I
>> have a (resolved) asynchronous observer method for it it will be
>> notified before the container closes no matter what.
> I think it's undefined. And I don't believe it would be reasonable to
> block the container shutdown because of an async observer method waiting
> for notification. The spec is clear that the container must destroy all
> contexts when an application is stopped. And if we destroy the contexts
> then the bean declaring the observer or its dependencies might be in
> inconsistent state.
>> (I believe I am observing a race condition somewhere in here that might
>> show that Weld's default asynchronous event delivery machinery does not
>> actually get around to delivering the event I've queued up before the
>> container closes. Sometimes the event is received, sometimes it is
>> not. Obviously if there is no such guarantee this could be permitted
>> cdi-dev mailing list
>> cdi-dev at lists.jboss.org
>> Note that for all code provided on this list, the provider licenses
>> the code under the Apache License, Version 2
>> (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas
>> provided on this list, the provider waives all patent and other
>> intellectual property rights inherent in such information.
Senior Software Engineer
Red Hat, Czech Republic
More information about the cdi-dev