1 Reply Latest reply on Jun 20, 2003 10:38 PM by Adrian Brock

    Deadlock Exception

    shmel Newbie

      I have 2 CMP2.0 Entity Beans, let's call them A and B.
      They are connected with the relation A(*)<--->(1)B.

      "A" has no any business logic methods: only accessors.

      When "B" calls method A.getX() I often receive exception "Application Deadlock".

      Please, how to prevent that?

        • 1. Re: Deadlock Exception
          Adrian Brock Master

          A deadlock is often caused by ordering problems

          Transaction1 lock A
          Transaction2 lock B
          Transaction1 A.tryToLockB()
          Transaction2 B.tryToLockA()
          Deadlock! Transaction1 holds A but wants B and
          Transaction2 holds B but wants A.

          1) Rearrange the access so that A is always before B
          or B is always before A
          2) The latest versions of JBoss will rollback transaction2
          which introduced the deadlock and retry it.
          3) Use read only access so that locks are maintained
          for very long if that fits your locking requirement
          4) Use optimistic locking and code for rollbacks.