8 Replies Latest reply on Sep 26, 2001 7:10 PM by dciarnie

    exceptions when multiple threads invoke create on the bean

    nishantv

      Hi all,
      I have run into the following problem:
      My client program starts multiple thread each creating
      'n' number of components. Each thread invokes create method on the bean. However I get exceptions. I guess i need to make some configurational changes in my jboss.jcml where I am creating connection pool.
      However I do not know what?
      Any pointers?
      BTW, when I run with single thread, it works just fine. When no. of threads is 2 or more exceptions are thrown.
      I am including the stack trace below:

      [StateComponentBean] XAException: tx=XidImpl [FormatId=257, GlobalId=cassini//5,
      BranchQual=] errorCode=XAER_NOTA
      [StateComponentBean] javax.transaction.xa.XAException
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAResourceImpl.
      start(XAResourceImpl.java:258)
      [StateComponentBean] at org.jboss.tm.TxCapsule.startResource(TxCapsule.java:1
      087)
      [StateComponentBean] at org.jboss.tm.TxCapsule.enlistResource(TxCapsule.java:
      614)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.enlistResource(Transacti
      onImpl.java:111)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAConnectionFactory.prepareObj
      ect(XAConnectionFactory.java:290)
      [StateComponentBean] at org.jboss.pool.ObjectPool.getObject(ObjectPool.java:5
      66)
      [StateComponentBean] at org.jboss.pool.ObjectPool.getObject(ObjectPool.java:5
      38)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAPoolDataSource.getConnection
      (XAPoolDataSource.java:178)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.getConnec
      tion(JDBCCommand.java:680)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecu
      te(JDBCCommand.java:152)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCStoreEntityComman
      d.execute(JDBCStoreEntityCommand.java:97)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.sto
      reEntity(JAWSPersistenceManager.java:168)
      [StateComponentBean] at org.jboss.ejb.plugins.CMPPersistenceManager.storeEnti
      ty(CMPPersistenceManager.java:397)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.storeEntity(EntityConta
      iner.java:252)
      [StateComponentBean] at org.jboss.ejb.plugins.EntitySynchronizationIntercepto
      r$InstanceSynchronization.beforeCompletion(EntitySynchronizationInterceptor.java
      :400)
      [StateComponentBean] at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.j
      ava:1210)
      [StateComponentBean] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:304)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.j
      ava:76)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
      tions(TxInterceptorCMT.java:364)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxI
      nterceptorCMT.java:86)
      [StateComponentBean] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(
      SecurityInterceptor.java:103)
      [StateComponentBean] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogIn
      terceptor.java:106)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.invokeHome(EntityContai
      ner.java:420)
      [StateComponentBean] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
      r.invokeHome(JRMPContainerInvoker.java:370)
      [StateComponentBean] at java.lang.reflect.Method.invoke(Native Method)
      [StateComponentBean] at sun.rmi.server.UnicastServerRef.dispatch(Unknown Sour
      ce)
      [StateComponentBean] at sun.rmi.transport.Transport$1.run(Unknown Source)
      [StateComponentBean] at java.security.AccessController.doPrivileged(Native Me
      thod)
      [StateComponentBean] at sun.rmi.transport.Transport.serviceCall(Unknown Sourc
      e)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unk
      nown Source)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.
      run(Unknown Source)
      [StateComponentBean] at java.lang.Thread.run(Unknown Source)
      [StateComponentBean] XAException: tx=XidImpl [FormatId=257, GlobalId=cassini//4,
      BranchQual=] errorCode=XAER_NOTA
      [StateComponentBean] javax.transaction.xa.XAException
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAResourceImpl.
      start(XAResourceImpl.java:258)
      [StateComponentBean] at org.jboss.tm.TxCapsule.startResource(TxCapsule.java:1
      087)
      [StateComponentBean] at org.jboss.tm.TxCapsule.enlistResource(TxCapsule.java:
      614)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.enlistResource(Transacti
      onImpl.java:111)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAConnectionFactory.prepareObj
      ect(XAConnectionFactory.java:290)
      [StateComponentBean] at org.jboss.pool.ObjectPool.getObject(ObjectPool.java:5
      66)
      [StateComponentBean] at org.jboss.pool.ObjectPool.getObject(ObjectPool.java:5
      38)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAPoolDataSource.getConnection
      (XAPoolDataSource.java:178)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.getConnec
      tion(JDBCCommand.java:680)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecu
      te(JDBCCommand.java:152)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCStoreEntityComman
      d.execute(JDBCStoreEntityCommand.java:97)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.sto
      reEntity(JAWSPersistenceManager.java:168)
      [StateComponentBean] at org.jboss.ejb.plugins.CMPPersistenceManager.storeEnti
      ty(CMPPersistenceManager.java:397)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.storeEntity(EntityConta
      iner.java:252)
      [StateComponentBean] at org.jboss.ejb.plugins.EntitySynchronizationIntercepto
      r$InstanceSynchronization.beforeCompletion(EntitySynchronizationInterceptor.java
      :400)
      [StateComponentBean] at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.j
      ava:1210)
      [StateComponentBean] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:304)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.j
      ava:76)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
      tions(TxInterceptorCMT.java:364)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxI
      nterceptorCMT.java:86)
      [StateComponentBean] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(
      SecurityInterceptor.java:103)
      [StateComponentBean] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogIn
      terceptor.java:106)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.invokeHome(EntityContai
      ner.java:420)
      [StateComponentBean] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
      r.invokeHome(JRMPContainerInvoker.java:370)
      [StateComponentBean] at java.lang.reflect.Method.invoke(Native Method)
      [StateComponentBean] at sun.rmi.server.UnicastServerRef.dispatch(Unknown Sour
      ce)
      [StateComponentBean] at sun.rmi.transport.Transport$1.run(Unknown Source)
      [StateComponentBean] at java.security.AccessController.doPrivileged(Native Me
      thod)
      [StateComponentBean] at sun.rmi.transport.Transport.serviceCall(Unknown Sourc
      e)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unk
      nown Source)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.
      run(Unknown Source)
      [StateComponentBean] at java.lang.Thread.run(Unknown Source)
      [StateComponentBean] XAException: tx=XidImpl [FormatId=257, GlobalId=cassini//4,
      BranchQual=] errorCode=XAER_PROTO
      [StateComponentBean] javax.transaction.xa.XAException
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAResourceImpl.
      end(XAResourceImpl.java:124)
      [StateComponentBean] at org.jboss.tm.TxCapsule.endResource(TxCapsule.java:112
      9)
      [StateComponentBean] at org.jboss.tm.TxCapsule.delistResource(TxCapsule.java:
      523)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.delistResource(Transacti
      onImpl.java:99)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.closeCon
      nection(XAConnectionFactory.java:104)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.connecti
      onClosed(XAConnectionFactory.java:89)
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAConnectionImp
      l.clientConnectionClosed(XAConnectionImpl.java:126)
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAClientConnect
      ion.close(XAClientConnection.java:250)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecu
      te(JDBCCommand.java:180)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCStoreEntityComman
      d.execute(JDBCStoreEntityCommand.java:97)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.sto
      reEntity(JAWSPersistenceManager.java:168)
      [StateComponentBean] at org.jboss.ejb.plugins.CMPPersistenceManager.storeEnti
      ty(CMPPersistenceManager.java:397)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.storeEntity(EntityConta
      iner.java:252)
      [StateComponentBean] at org.jboss.ejb.plugins.EntitySynchronizationIntercepto
      r$InstanceSynchronization.beforeCompletion(EntitySynchronizationInterceptor.java
      :400)
      [StateComponentBean] at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.j
      ava:1210)
      [StateComponentBean] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:304)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.j
      ava:76)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
      tions(TxInterceptorCMT.java:364)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxI
      nterceptorCMT.java:86)
      [StateComponentBean] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(
      SecurityInterceptor.java:103)
      [StateComponentBean] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogIn
      terceptor.java:106)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.invokeHome(EntityContai
      ner.java:420)
      [StateComponentBean] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
      r.invokeHome(JRMPContainerInvoker.java:370)
      [StateComponentBean] at java.lang.reflect.Method.invoke(Native Method)
      [StateComponentBean] at sun.rmi.server.UnicastServerRef.dispatch(Unknown Sour
      ce)
      [StateComponentBean] at sun.rmi.transport.Transport$1.run(Unknown Source)
      [StateComponentBean] at java.security.AccessController.doPrivileged(Native Me
      thod)
      [StateComponentBean] at sun.rmi.transport.Transport.serviceCall(Unknown Sourc
      e)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unk
      nown Source)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.
      run(Unknown Source)
      [StateComponentBean] at java.lang.Thread.run(Unknown Source)
      [StateComponentBean] XAException: tx=XidImpl [FormatId=257, GlobalId=cassini//5,
      BranchQual=] errorCode=XAER_PROTO
      [StateComponentBean] javax.transaction.xa.XAException
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAResourceImpl.
      end(XAResourceImpl.java:124)
      [StateComponentBean] at org.jboss.tm.TxCapsule.endResource(TxCapsule.java:112
      9)
      [StateComponentBean] at org.jboss.tm.TxCapsule.delistResource(TxCapsule.java:
      523)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.delistResource(Transacti
      onImpl.java:99)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.closeCon
      nection(XAConnectionFactory.java:104)
      [StateComponentBean] at org.jboss.pool.jdbc.xa.XAConnectionFactory$2.connecti
      onClosed(XAConnectionFactory.java:89)
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAConnectionImp
      l.clientConnectionClosed(XAConnectionImpl.java:126)
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAClientConnect
      ion.close(XAClientConnection.java:250)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecu
      te(JDBCCommand.java:180)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCStoreEntityComman
      d.execute(JDBCStoreEntityCommand.java:97)
      [StateComponentBean] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.sto
      reEntity(JAWSPersistenceManager.java:168)
      [StateComponentBean] at org.jboss.ejb.plugins.CMPPersistenceManager.storeEnti
      ty(CMPPersistenceManager.java:397)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.storeEntity(EntityConta
      iner.java:252)
      [StateComponentBean] at org.jboss.ejb.plugins.EntitySynchronizationIntercepto
      r$InstanceSynchronization.beforeCompletion(EntitySynchronizationInterceptor.java
      :400)
      [StateComponentBean] at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.j
      ava:1210)
      [StateComponentBean] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:304)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.j
      ava:76)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
      tions(TxInterceptorCMT.java:364)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxI
      nterceptorCMT.java:86)
      [StateComponentBean] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(
      SecurityInterceptor.java:103)
      [StateComponentBean] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogIn
      terceptor.java:106)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.invokeHome(EntityContai
      ner.java:420)
      [StateComponentBean] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
      r.invokeHome(JRMPContainerInvoker.java:370)
      [StateComponentBean] at java.lang.reflect.Method.invoke(Native Method)
      [StateComponentBean] at sun.rmi.server.UnicastServerRef.dispatch(Unknown Sour
      ce)
      [StateComponentBean] at sun.rmi.transport.Transport$1.run(Unknown Source)
      [StateComponentBean] at java.security.AccessController.doPrivileged(Native Me
      thod)
      [StateComponentBean] at sun.rmi.transport.Transport.serviceCall(Unknown Sourc
      e)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unk
      nown Source)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.
      run(Unknown Source)
      [StateComponentBean] at java.lang.Thread.run(Unknown Source)
      [StateComponentBean] XAException: tx=XidImpl [FormatId=257, GlobalId=cassini//5,
      BranchQual=] errorCode=XAER_NOTA
      [StateComponentBean] javax.transaction.xa.XAException
      [StateComponentBean] at org.opentools.minerva.jdbc.xa.wrapper.XAResourceImpl.
      rollback(XAResourceImpl.java:210)
      [StateComponentBean] at org.jboss.tm.TxCapsule.rollbackResources(TxCapsule.ja
      va:1539)
      [StateComponentBean] at org.jboss.tm.TxCapsule.commit(TxCapsule.java:346)
      [StateComponentBean] at org.jboss.tm.TransactionImpl.commit(TransactionImpl.j
      ava:76)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
      tions(TxInterceptorCMT.java:364)
      [StateComponentBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxI
      nterceptorCMT.java:86)
      [StateComponentBean] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(
      SecurityInterceptor.java:103)
      [StateComponentBean] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogIn
      terceptor.java:106)
      [StateComponentBean] at org.jboss.ejb.EntityContainer.invokeHome(EntityContai
      ner.java:420)
      [StateComponentBean] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
      r.invokeHome(JRMPContainerInvoker.java:370)
      [StateComponentBean] at java.lang.reflect.Method.invoke(Native Method)
      [StateComponentBean] at sun.rmi.server.UnicastServerRef.dispatch(Unknown Sour
      ce)
      [StateComponentBean] at sun.rmi.transport.Transport$1.run(Unknown Source)
      [StateComponentBean] at java.security.AccessController.doPrivileged(Native Me
      thod)
      [StateComponentBean] at sun.rmi.transport.Transport.serviceCall(Unknown Sourc
      e)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unk
      nown Source)
      [StateComponentBean] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.
      run(Unknown Source)
      [StateComponentBean] at java.lang.Thread.run(Unknown Source)
      [EntitySynchronizationInterceptor] Store failed
      java.rmi.ServerException: Store failed; nested exception is:
      java.sql.SQLException: [ARES]Your transaction (process ID #7) was deadlo
      cked with another process and has been chosen as the deadlock victim. Rerun your
      transaction.
      java.sql.SQLException: [ARES]Your transaction (process ID #7) was deadlocked wit
      h another process and has been chosen as the deadlock victim. Rerun your transac
      tion.
      at com.inet.tds.a.a(Unknown Source)
      at com.inet.tds.b.for(Unknown Source)
      at com.inet.tds.b.executeUpdate(Unknown Source)
      at org.opentools.minerva.jdbc.PreparedStatementInPool.executeUpdate(Prep
      aredStatementInPool.java:82)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCUpdateCommand.executeStatementAnd
      HandleResult(JDBCUpdateCommand.java:49)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecute(JDBCCommand.j
      ava:160)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCStoreEntityCommand.execute(JDBCSt
      oreEntityCommand.java:97)
      at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.storeEntity(JAWSPer
      sistenceManager.java:168)
      at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenc
      eManager.java:397)
      at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:252)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor$InstanceSynchr
      onization.beforeCompletion(EntitySynchronizationInterceptor.java:400)
      at org.jboss.tm.TxCapsule.doBeforeCompletion(TxCapsule.java:1210)
      at org.jboss.tm.TxCapsule.commit(TxCapsule.java:304)
      at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:76)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:364)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.ja
      va:86)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
      tor.java:103)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
      06)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:420)
      at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRM
      PContainerInvoker.java:370)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
      at sun.rmi.transport.Transport$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
      ce)
      at java.lang.Thread.run(Unknown Source)

        • 1. Re: exceptions when multiple threads invoke create on the be
          psalur

          USE JBOSS2.2.2 and see the magic !!!!!!!!

          BAmBU

          • 2. Re: exceptions when multiple threads invoke create on the be
            nhebert

            Nishant,

            Are the threads attempting to share the *same* home
            instance, or are you obtaining a home instance for
            each thread?

            At first blush, me thinks the first scenario is not
            a good idea.

            Cheers,

            Noel.

            • 3. Re: exceptions when multiple threads invoke create on the be
              nitesh

              Noel,

              We used the same home reference in all the threads. But it shouldn't matter whether the home instance is obtained from JNDI once and shared among all the threads, or each thread obtains the home reference from the JNDI independently. At the end of it, in either case, it is the same remote reference that you are getting from the naming service.

              Thanks,

              Nitesh

              • 4. Re: exceptions when multiple threads invoke create on the be
                nhebert

                Nitesh,

                You are correct. My fingers went flying across the
                keyboard to answer the question before the brain
                engaged. ;-)

                Somewhere nishant has a concurrency problem and I
                jumped on that as the first canidate. Further eyeballs
                on his code may uncover where it is coming unstuck...

                Cheers,

                Noel.

                • 5. Re: exceptions when multiple threads invoke create on the be

                  I have also run across this problem. Has anyone yet figured out what the problem might be?

                  Here is some sample test code that I've used to illustrate the problem:


                  public class ejbtest
                  {
                   public final int nthreads = 3;
                  
                   public ejbtest()
                   {
                   test1();
                  // test2();
                  // test3();
                   }
                  
                   private void test1()
                   {
                   Thread threads = new Thread[nthreads];
                   int i = 0;
                   for(i=0; i<nthreads; ++i)
                   {
                   threads = new EJBThreadedCreateTest(i);
                   }
                   for(i=0; i<nthreads; ++i)
                   {
                   threads.start();
                   }
                   }
                  
                   private void test2()
                   {
                   Thread threads = new Thread[nthreads];
                   int i = 0;
                   for(i=0; i<nthreads; ++i)
                   {
                   threads = new EJBThreadedAccessTest(i);
                   }
                   for(i=0; i<nthreads; ++i)
                   {
                   threads.start();
                   }
                   }
                  
                   private void test3()
                   {
                   Thread threads = new Thread[nthreads];
                   int i = 0;
                   for(i=0; i<nthreads; ++i)
                   {
                   threads = new EJBThreadedRemoveTest(i);
                   }
                   for(i=0; i<nthreads; ++i)
                   {
                   threads.start();
                   }
                   }
                  
                   public static void main(String[] args)
                   {
                   ejbtest ejbtest1 = new ejbtest();
                   }
                  }
                  
                  class EJBThreadedCreateTest extends Thread
                  {
                   private int startid = 0;
                  
                   public EJBThreadedCreateTest(int _startid)
                   {
                   startid = _startid;
                   }
                  
                   public void run()
                   {
                   try
                   {
                   // Get home interface
                   int i=0;
                   for(i=0; i<10; ++i)
                   {
                   String id = Integer.toString(10*startid+i);
                   EJBRemote remote = home.create(id);
                   }
                   }
                   catch(Exception e)
                   {
                   System.out.println(e.toString);
                   }
                   }
                  }
                  
                  class EJBThreadedAccessTest extends Thread
                  {
                   private int startid = 0;
                  
                   public EJBThreadedAccessTest(int _startid)
                   {
                   startid = _startid;
                   }
                  
                   public void run()
                   {
                   try
                   {
                   // Get home interface
                   int i=0;
                   for(i=0; i<10; ++i)
                   {
                   String id = Integer.toString(10*startid+i);
                   EJBRemote remote = home.findByPrimaryKey(id);
                   System.out.println(remote.getValue());
                   }
                   }
                   catch(Exception e)
                   {
                   System.out.println(e.toString);
                   }
                   }
                  }
                  
                  class EJBThreadedRemoveTest extends Thread
                  {
                   private int startid = 0;
                  
                   public EJBThreadedRemoveTest(int _startid)
                   {
                   startid = _startid;
                   }
                  
                   public void run()
                   {
                   try
                   {
                   // Get home interface
                   int i=0;
                   for(i=0; i<10; ++i)
                   {
                   String id = Integer.toString(10*startid+i);
                   home.remove(id);
                   }
                   }
                   catch(Exception e)
                   {
                   System.out.println(e.toString);
                   }
                   }
                  }
                  


                  I don't think that this code has any concurrency problems and the way that I've set up the tests, each bean gets accessed once and only once (from the client's perspective).

                  If I set nthreads to 1, each of the tests runs without error. However, for 2 or more threads, I get exceptions very similar to the one's nshantv gives above.

                  I've noticed that for the most part, the exceptions are not propagated to the client. For instance, I've seen numerous exceptions during the create tests but the client does not see them and the beans seem to be created properly. However, the occasional exception that occurs during the remove tests is propagated to the client and the bean is not removed (or, at least, the data in the database is not removed).

                  Anyway, if anyone can shed some light on the problem I would appreciate it.

                  Thanks,
                  Dan.


                  • 6. Re: exceptions when multiple threads invoke create on the be
                    nitesh

                    There is no synchronization problem. I think the problem lies with the JBOSS 2.4.1 transaction manager.

                    Try using JBOSS 2.2.2 and see if it works or not. Our tests started to work when we switched to JBoss 2.2.2. However, when the number of threads exceed 20 or so, the tests start getting sporadic java.sql.ConnectException: Connection refused by host.

                    Thanks,

                    Nitesh

                    • 7. Re: exceptions when multiple threads invoke create on the be

                      Well, I tried the tests with 2.2.2 and found that the exceptions still occur. The main difference is a matter of degree. In 2.2.2, I don't get the exceptions at all with the access tests and the exceptions are much rarer with the create tests. With the remove tests, the exceptions occur just about as frequently as with 2.4.1 but fewer make it back to the client.

                      Dan.

                      • 8. Re: exceptions when multiple threads invoke create on the be

                        Well, I finally figured out the problem. With some liberal sprinkling of println()'s throughout the code (ain't open source great?) I discovered the reason for the exceptions:

                        I had GCMinIdleTime in my connection pool configuration in jboss.jcml set so low that the connection was being returned to the pool before the transaction was committed and the associated resource released.

                        With single-threaded client access, this does not pose a problem since the client cannot invoke any methods on the bean requiring a connection before the previous mthod invocation is completed. In a multi-threaded (or multiple client access) situation, it is, of course, possible that a request comes in and grabs the recently returned connection from the pool before the resource was released. This caused the exceptions to be thrown.

                        Anyway, the "fix" is to ensure that GCMinIdleTime is set to a large enought value. For some strange reason, mine was set to 20 ms which is far too short.

                        Dan.