2 Replies Latest reply on Aug 14, 2002 9:43 AM by Dmitri Colebatch

    read only methods

    Dmitri Colebatch Newbie

      Hi,

      This is mainly a question in relation to the thread http://www.mail-archive.com/jboss-user@lists.sourceforge.net/msg18814.html//www.mail-archive.com/jboss-user@lists.sourceforge.net/msg18814.html

      I'm running on 3.0RC1/Sun1.3/2k/Postgres7.2.

      I'm not 100% if what I'm trying to do should work - but it makes sense. Basically I have a deadlock detection exception raised on a getId() method which is obviously a readonly method. So I found this email from Bill and tried to make it work (btw - the DTD doesn't permit this, should it?).

      Here's the relevant snippet from jboss.xml:


      <ejb-name>Page</ejb-name>
      <local-jndi-name>Page</local-jndi-name>
      <resource-ref>
      <res-ref-name>jdbc/DataSource</res-ref-name>
      <resource-name>java:/PostgresDS</resource-name>
      </resource-ref>
      <method-attributes>

      <method-name>getId</method-name>
      <read-only>true</read-only>

      </method-attributes>


      and part of the stack trace:

      22:25:46,499 ERROR [BeanLock] Application deadlock detected: TransactionImpl:Xid
      Impl [FormatId=257, GlobalId=hobbes//300, BranchQual=] has deadlock conditions
      22:25:46,499 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
      org.jboss.ejb.plugins.lock.ApplicationDeadlockException: application deadlock de
      tected
      at org.jboss.ejb.plugins.lock.BeanLockSupport.deadlockDetection(BeanLock
      Support.java:190)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.waitForTx(QueuedP
      essimisticEJBLock.java:282)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.doSchedule(Queued
      PessimisticEJBLock.java:189)
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.schedule(QueuedPe
      ssimisticEJBLock.java:140)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:103)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
      Interceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:176)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
      1)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:129)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:183)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
      lContainerInvoker.java:296)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      at $Proxy707.getId(Unknown Source)
      at net.sportspaper.cma.ejb.StoryEJB.publish(StoryEJB.java:142)

      line 142 of StoryEJB is this:

      Long id = storyPage.getId();

      (broken into one line to identify for sure what the problem was).

      Could someone confirm/deny that what I'm trying to do should work, and maybe point out what I'm doing wrong?

      cheers
      dim

      ps - what happened to support for

      in the forum?


        • 1. Re: read only methods
          Dmitri Colebatch Newbie

          Replying to my own thread in a hope to spark some interest.

          I've had a look at the code, specificially this (http://www.mail-archive.com/jboss-development@lists.sourceforge.net/msg24074.html//www.mail-archive.com/jboss-development@lists.sourceforge.net/msg24074.html) change, and come to the conclusion that a read-only method in a bean makes no difference to the lock _unless_ the entire tx is readonly.

          example:

          a.foo() // normal r/w method
          b.bar() // r/o method

          a.foo() calls b.bar()

          b is locked until the tx is finished.

          is this correct?

          secondly - assuming it is correct - is it required? Why do we need to lock b for any more than the method call if we know that b does not change in the tx?

          here is the code (from QueuedPessimisticEJBLock) that leads me to this conclusion:

          // Promote the txlock into a writeLock if we're not a readonly method
          // isReadOnlyTxLock will be reset in nextTransaction()
          Method method = mi.getMethod();
          isReadOnlyTxLock =
          isReadOnlyTxLock &&
          (
          ((EntityContainer)container).isReadOnly() ||
          (
          method != null &&
          container.getBeanMetaData().isMethodReadOnly(method.getName())
          )
          );

          thanks in advance,
          cheers
          dim

          • 2. Re: read only methods
            Dmitri Colebatch Newbie

            I've had a look at the code, specificially this
            (http://www.mail-archive.com/jboss-development@lists.sourceforge.net/msg2407//www.mail-archive.com/jboss-development@lists.sourceforge.net/msg2407
            4.html) change, and come to the conclusion that a read-only method in a bean
            makes no difference to the lock _unless_ the entire tx is readonly.

            example:

            a.foo() // normal r/w method
            b.bar() // r/o method

            a.foo() calls b.bar()

            b is locked until the tx is finished.

            is this correct?

            secondly - assuming it is correct - is it required? Why do we need to lock
            b for any more than the method call if we know that b does not change in the
            tx?

            here is the code (from QueuedPessimisticEJBLock) that leads me to this
            conclusion:

            // Promote the txlock into a writeLock if we're not a readonly
            method
            // isReadOnlyTxLock will be reset in nextTransaction()
            Method method = mi.getMethod();
            isReadOnlyTxLock =
            isReadOnlyTxLock &&
            (
            ((EntityContainer)container).isReadOnly() ||
            (
            method != null &&

            container.getBeanMetaData().isMethodReadOnly(method.getName())
            )
            );

            thanks in advance,
            cheers
            dim