1 Reply Latest reply on Jul 22, 2003 7:04 PM by Adrian Brock

    Concurrency problem with BMP entity beans

    Norton Newbie


      We are having a concurrency issue with our BMP entity beans.
      We have two servlets, one calls the other to simulate a call to
      an external source. Right now, they live in the same deployment
      for testing purposes and use the same core EJB and other java classes.

      Both servlets do different operations on the same data, so both call a
      particular EJB with the same primary key. The first servlet, we'll call servlet A, gets the
      EJB with primary key '1', does its thing and passes the key '1' to the
      second servlet, servlet B. Servlet B then wants to get the same EJB
      with primary key '1' and do its operations before returning to servlet A.
      Servlet A spawns a new thread to call servlet B so that it can set a timeout limit
      on the response.

      What we're seeing is that servlet B can't get a hold of the EJB until servlet
      A times out and completes its operations (reporting an error from servlet B).
      Once servlet A's wait loop is complete, servlet B goes on its merry way and
      finishes what it needs to do.

      I've tried this on both jboss-3.0.6 and 3.2.2RC1 on a RedHat Linux 7.3 box.
      In 3.0.6, the above scenario occurs. In 3.2.2, the servlet A finishes, but servlet
      B never does. I think we are getting a StackOverflowError from servlet B, but
      I haven't tried to pin that down yet.

      We see this same behavior with another servlet, servlet C, which can get called
      multiple times from different instances of the same client. Everything works fine
      if the calls to servlet C are made a few seconds apart. However, if servlet C is
      called nearly simultaneously, the first spawned servlet C thread hangs on to
      the EJB that all instances of servlet C need and the remaining servlet C threads
      eventually timeout, even after the first thread finishes. (This scenario was
      only tried on 3.0.6).

      My theory is that servlet A, or the first thread of servlet C gets a hold of the EJB
      with the primary key that all threads are trying to use and won't let go of it. As I
      understand it JBoss will use the same EJB instance for all calls to that EJB with the
      same primary key. If that's the case, it would make sense that no other threads
      could use the EJB until the first thread is finished with it.

      I've tried changing the commit-options in standardjboss.xml for all BMPs to commit
      option C, but that didn't help.

      So my questions are:

      Is my theory correct?
      If so, is there a way to ask JBoss to create multiple instances of an EJB with the same primary key?
      Was my attempt to change the commit option the right approach and if so, why didn't it work?
      Is there a different solution?

      Thank you in advance for your help.