2 Replies Latest reply on Apr 29, 2002 9:09 AM by Brian Dobby

    Problem: Tx shared between threads: JBoss 2.4.3 & JSQLConnec

    Brian Dobby Newbie

      Hi, we seem to have a situation where calls to JBoss from 2 threads of the same client app are getting the same transaction when getting connections from the same pool. Both threads are calling stateless session beans, one with BMT and one with CMT. Log output from TxCapsule shows that transactions on the threads are assigned different global ids:

      TxCapsule: Reused instance for tx=XidImpl [FormatId=257, GlobalId=bdobby//78, BranchQual=] (Global id is different on each thread)

      but datasource logging appears to show that the same connection is handed out in each thread, enlisted in the same tx:

      Resource 'com.jnetdirect.jsql.JSQLXAResource@fa09bd' enlisted or 'com.jnetdirect.jsql.JSQLXAConnection@fa0fa3'.
      Pool Nobilis [1/2/Unlimited] gave out pooled object: com.jnetdirect.jsql.JSQLXAConnection@fa0fa3
      Pool Nobilis [0/2/Unlimited] returned object com.jnetdirect.jsql.JSQLXAConnection@fa0fa3 to the pool.

      (these ids are the same on each thread).

      Our EJBs hold a connection for the shortest possible time, usually one statement execution, though they may execute several statements during a method call (either directly or by calling entity beans or CMT session beans).

      Surely the connection pool should ensure that a connection enlisted in a transaction is only handed out to the thread that started the transaction?

      Has anyone seen this behaviour, or have any idea what we may be doing wrong?

        • 1. Re: Problem: Tx shared between threads: JBoss 2.4.3 & JSQLCo
          David Jencks Master

          Are you are using an XADataSource?

          With xa, many transactions can use the same connection, one after the other. When you commit a particular transaction, you identify it by id so the db knows what work to commmit -- the work associated with that id, no matter which connection it came over.

          Are there any actual errors or are you just surprised?

          • 2. Re: Problem: Tx shared between threads: JBoss 2.4.3 & JSQLCo
            Brian Dobby Newbie

            1. We are using xa, because we may sometimes need to enlist multiple datasources in the tx.

            2. How can a BMT bean commit by id? UserTransaction does not make the id available, and commit() takes no arguments.

            3. We are getting application errors because, for example:
            a. thread 1 creates an entity (BMT)
            b. thread 2 runs a query (CMT) and its tx commits
            c. because thread 2 used the same tx as thread 1,
            the entity is now visible in the db before other
            work on thread 1 is complete.