2 Replies Latest reply on Jul 30, 2004 4:40 AM by morenito9000

    Entity Beans and row-locking

    morenito9000

      Hi all,
      I have 2 clients that call a stateful session bean's method.

      Inside this method the session bean starts a transaction and
      then retrieves/update an entity bean.

      The behaviour of the method differs depending
      the client that called it.

      In particular, for Client 1 the method performs this steps:

      1) retrieves the entity bean (with findByPrimaryKey())
      2) sleeps for 45 seconds
      3) updates the entity bean

      For Client 2 the steps are:

      1) retrieves the entity bean (with findByPrimaryKey())
      2) updates IMMEDIATELY the entity bean

      I'm doing some tests about competion among these 2 clients.
      I run Client 1 and after few seconds I run Client 2.

      I expect that Client 2 ends before Client 1 but the strange
      thing is that Client 2 waits till the end of the sleep(45) of
      Client 1 !!

      I'm non able to understand this behaviour :-(

      I'd have understood it if there had been a
      <row-locking> tag with TRUE value in the
      defaults section of standardjbosscmp-jdbc.xml file,
      but this tag is set to FALSE.

      <defaults>
       <datasource>java:/PostgresDS</datasource>
       <datasource-mapping>PostgreSQL</datasource-mapping>
      
       <create-table>false</create-table>
       <remove-table>false</remove-table>
       <read-only>false</read-only>
       <read-time-out>300000</read-time-out>
       <row-locking>false</row-locking>
      


      Can anyone give me an explanation ?

      Many thanks
      Moreno

        • 1. Re: Entity Beans and row-locking
          aloubyansky

          This is because of pessimistic locking. Check the JBossCMP wiki Locking page.

          • 2. Re: Entity Beans and row-locking
            morenito9000

            Thank you Loubyansky !

            I read the JBoss book's pages concerning Optimistic-Locking.

            If I wanna Optimistic-Locking I must use, for my entity bean,
            a Container-Configuration like 'Instance per Transaction...."
            and define the fields in my bean that I'll use for optimistic-locking policy
            (I hope I understood well :-))

            Just only two questions:
            1) if I declare to use Optmistic-Locking
            it has no sense to set the row-locking tag to TRUE ?

            2) And if I don't wanna Optimistic-Locking I must do
            nothing (that is the default behaviour)
            like I experimented with the "two beans" test ?

            Thanks again
            Moreno