Search code examples
jboss5.xjava-ee-5xa

Using both XA and non-XA datasource for the same database


There are some places in our project where we need to use XA transactions. But in most of the project the regular non-XA datasource will do. I've been wondering, do I need to define 2 versions of the datasource, XA and non-XA, for the same database? I'm afraid that XA transactions could be costly, therefore I'd like to avoid them if possible.


Solution

  • That's a very reasonable approach if you are worried about performance, as the 2PC commit protocol can be up to 4 times slower. Of course this needs to be qualified

    • this depends on the number of resource managers that are participating in the xa txn
    • 2PC itself is more expensive as it requires more roundtrips.

    In addition transactions can go into the in-doubt state when a failure occurs, which essentially locks all records that were changed as part of the transaction until they are recovered. By not using XA this can be avoided.