Search code examples
javatransactionsjtaxa

If a XAResource is the only resource involved in a Tx should the XAResource.prepare() be called


I am trying out a few things w/ JOTM and have some general purpose questions regarding how things work. I have listed the sequence of events to get a definitive summary of what happens.

  1. create tx
  2. enlist resource
  3. tx.commit
  4. resource.start
  5. resource.end
  6. resource.commit

Why is resource.prepare never called and the flag to commit (onephase) is true. Is this the intended behaviour for such use cases ?


Solution

  • Why is resource.prepare never called and the flag to commit (onephase) is true

    XA specification section 2.3.2:

    One-phase Commit A TM can use one-phase commit if it knows that there is only one RM anywhere in the DTP system that is making changes to shared resources. In this optimisation, the TM makes its Phase 2 commit request without having made a Phase 1 prepare request.

    Is this the intended behaviour for such use cases ?

    yes