[cdi-dev] CDI 2.0 EDR: Questions on asynchronous observers

Jozef Hartinger jharting at redhat.com
Wed Aug 12 04:32:35 EDT 2015

On 11.8.2015 17:33, Nigel Deakin wrote:
> I've read section 10 "Events" of the CDI 2.0 early draft, and have a couple of quick questions about asynchronous
> observers.
> I'd like to understand how these work with transactions. (I'm referring to normal observer methods here, not the rather
> specialised "transactional observer methods")
> 10.5 states "...An observer method may not directly initiate, commit or rollback JTA transactions."
> This wording is unchanged from CDI 1.1. What is the reason for this restriction? I think it might be useful if an
> observer method was able to use the JTA API to start and end a transaction, especially when the observer method is being
> called asynchronously.

I think this is just an oversight and this statement was not updated in 
the light of CDI 2.0 (although it should have).

> 10.5.3 "If the observer method is asynchronous, it is called in... a new transaction context...".
> What does "a new transaction context" mean? Does this mean that the container will start a transaction before calling
> the observer method? If so, it would be useful if the application could disable this. If not, it would be useful if the
> application could itself use the JTA API to start and end a transaction.

I think that what this statement is trying to say is simply that the 
transactional context of the event sender is not propagated to the async 

The observer should IMO be able to work with the transactional context 
using EJB managed transactions, @Transactional or manually with 

> Nigel
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
> 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.

More information about the cdi-dev mailing list