5 Replies Latest reply on Jun 9, 2007 3:47 AM by marklittle

    Transaction control across multiple threads

      Is it possible to to use UserTransaction to control database operations across multiple threads:

      In main thread:

      userTrx = getUserTransaction();
      userTrx.begin();

      create one or more worker thread to read/write to the database.

      wait till all worker thread are done.

      userTrx.commit or rollback.

      Thanks.

        • 1. Re: Transaction control across multiple threads
          marklittle

          If you want all of the threads to be doing work in the scope of the same transaction then you will have to get the UserTransaction within each thread and do a resume on the required transaction in order to associate it with the thread (and vice versa).

          JTA does not provide any means for you to do thread synchronization at transaction commit. However, JBossTS provides a CheckedAction class, an instance of which is associated with each transaction. If you check the Programmers Guide about this you should be able to figure out how to get it to do what you want.

          • 2. Re: Transaction control across multiple threads

            How do I call resume, I have tried to lookup the TransactionManager with "TransactionManager", "javax.transaction.TransactionManager" and "java:/TransactionManager", but always get a "not bound" exception, is TransactionManager only available on the server side and client has no way to access it?

            Thanks.

            • 3. Re: Transaction control across multiple threads
              marklittle

              What is your deployment? Which version of JBossAS? Which version of JBossTS? Which JTA implementation within JBossTS? More information is required in order to help you further.

              • 4. Re: Transaction control across multiple threads

                I have stateless session beans deployed on JBoss 4.0.3 SP1, with whichever JBossTS, JTA build in with the "all" configuration (i.e. no Aljuna).

                Regards,

                • 5. Re: Transaction control across multiple threads
                  marklittle

                  OK, so for a start I'd recommend you download JBossTS and install it into your AS installation. That way you'll get the synchronization capability I mentioned earlier.