I am working with JBoss EAP 6.4 (Java EE 6) and I have a question related to the way the application server is dealing with XA Datasources (through EJB / JTA) and if the 2 phase commit (2PC) is always used or if an "optimization" is applied.
Let's say I have this:
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyEjb {
@EJB
private MyFirstEjb first;
@EJB
private MySecondEjb second;
// Transactional processing
public void process() {
first.processJpaStuff();
second.processJpaStuff();
}
}
Let's say that :
- MyFirstEjb do JPA queries using XA Datasource 1.
- MySecondEjb do JPA queries using XA Datasource 2.
I am using XA datasource because these EJBs can be used in other cases where 2PC is required (along with another datasource or a JMS provider).
I now would like to distinguish several cases:
- MyFirstEjb and MySecondEjb are deployed in the same application (EAR)
- MyFirstEjb and MySecondEjb are deployed in separate applications (EARs) within the same application server
- MyFirstEjb and MySecondEjb are deployed within different applications servers
and sub-cases:
a) XA Datasource 1 = XA Datasource 2
b) XA Datasource 1 != XA Datasource 2 (same database)
c) XA Datasource 1 != XA Datasource 2 (different database)
I guess b) and c) are managed the same way. There is a global transaction and each datasource collaborate with the XA transaction manager. A 2PC is applied.
What about cases 1.a) and 2.a) ? Since both are eventually using the same datasource, I guess there is some kind of optimization that does not require a global 2PC transaction to be processed? If yes, is there any official (JTA / JBoss / ...) link that explains this? Is it the same thing with all application servers / implementations?
Thanks