4 Replies Latest reply: Dec 14, 2012 2:17 AM by jboss.new.user RSS

How more than one XA Datasources participate in one container managed transaction ?

jboss.new.user Newbie

Hi guys,

 

Recently I am involved in dealing with distributed transaction with JBoss 5.1 wherein Container Managed Transaction is used. But my worry is I am not understanding how different xa-resources are participating in the distributed transaction managed by JBossTS transaction manager. Basically I am looking for what are the transaction boundaries. And where I should put my code which I want to be executed as part of the transaction ? And also how container would understand which bean belongs to which xa-datasource.

If somebody can give or point me to any example where more than one XA Datasource participates in one Container Managed Transaction then that would be much helpful. If any help is there w.r.t. JBoss 7 then that would be of much use as well.

I have already googled and tried to get something from JBoss documentation but couldn't find anything useful.

I already know how to configure datasources and transaction manager.

Any help would be appreciated.

Thanks in advance.

  • 1. Re: How more than one XA Datasources participate in one container managed transaction ?
    Wolf-Dieter Fink Master

    You should clarify what you mean by distributed transaction.

     

    If the transaction use different JCA connections inside the server the only thing is to have all such resources handle XA (two phase commits) correct.

    Also a client can initiate the Tx if it is using the same server (you need transaction stickyness in this case).

     

    If you mean that the Tx span different server instances, i.e. two EJB's on different servers you need to have a JTS configuration instead of the  (default) JTA. There are scripts in the docs directory to change the configuration.

  • 2. Re: How more than one XA Datasources participate in one container managed transaction ?
    jboss.new.user Newbie

    Hi Fink,

     

    Thanks for replying.

     

    Let's take this to elaborate a little.

     

    JBoss AS is configured for JTS. One XA datasource is on dataSourceServer A and another XA datasource is on dataSourceServer B. All my EJBs are there on the same JBoss server (same node, single instance). Just for the sake of simplicity something is needed to be done on datasource A and datasource B where actionA and actionB corresponds to datasource A and datasource B respectively. Here actionA & actionB should be done as a part of one single transaction.

     

    Now in case of BMT we can get the datasource via JNDI lookup and do the operation and complete the transaction by using TransactionManager of the JBoss or even by using XAResource and its lifecycle methods for two-phase commit.

     

    But in case of CMT how we are going to achieve this. This is the point of confusion for me. How in case of CMT transactionManager will call the methods of two-phase commit ? How it will understand that which XA--Datasources are involved (is there any way to configure this ?) ?

  • 3. Re: How more than one XA Datasources participate in one container managed transaction ?
    Wolf-Dieter Fink Master

    If you use CMT the container will track which resource is involved in the transaction.

    If the EJB is finished (mean that the business method return) the container will send a prepare to all XA resources and if successful a commit.

    It is the responsibility of the container how to do this. AFAIK JBoss will send prepare/commit in that order the resources are got from the container( but this might change with different versions).

     

    Also if you use different resources from an EJB, or a couple of EJB's, inside the same JBoss instance you do not need a JTS configuration. It will be more complex and might have performance drawbacks as it uses IIOP.

     

    So a Tx is committed if you return from a method with a different Tx scope, let me shown an example:

     

    Method1 (Tx.Required)

       do DB stuff

      -> M2 (Tx.NotSupported)

          Tx1 suspended

       -> M3 (Tx.Required)

            Tx2

           do DB stuff maybe different DB'S

           return

       <-  (prepare)commit Tx2

       <-

    <-

    (prepare)commit Tx1

     

    The commits are done by the container outside your code (also outside the interceptors)

    There is no configuration to control that.