3 Replies Latest reply on Feb 17, 2003 3:33 AM by Steinar Overbeck Cook

    Concurrency/CMP 2.x problem in Jboss

    Omar Belakhdar Newbie

      Hi jbossers,
      I'm using jboss for my courses at the swiss federal institute of technology. My config is as follows:
      1 - jboss 3.0.4.
      2 - Postgres 7.3 (It works fine with jboss).
      3 - Linux Mandrake 9.0

      I've created only one simple Entity Bean called "Item" with three attributes (barcode, type, status) with one of them as a primary key.
      Then I created a findByStatus method to look for an entity by its status. The SQL statment I used is "Select Object(o) from
      Item o where o.status=?1".
      I used a row-lock to lock the row during update.

      When I tried to access the entity using one test client, all things work fine. However when I tried to access the bean using to different clients, the concurrency is not respected since one client or both of them delete the updated value that one of them has entered.

      When I looked to the server log file I find the following strange behavior of jboss:

      First when I request the bean, the server just make I "select ..." without a "for Update" at the end of the statment beacuse I specified a row-lock to true. But one I tried to update the value of an attribute it appends the "for update" at the end of the statement. This justify why I'm getting the rong result at the end.

      Is this a problem of jboss or I'm messing some thing?

      What I wish to do is to get a "select ... for update" for the first read because I want to read the attribute and them modify it after.

      Thanks for your help.

      Omar.

        • 1. Re: Concurrency/CMP 2.x problem in Jboss
          Stephen Coy Novice

          Hi,

          This is why they invented transactions.

          You need to learn about EJB transactions and commit options.

          Typically, you would code your "business interface" in a session bean, and give the method a trx attribute of "Requires New". The session bean method then performs all activities on the entity bean within the scope of a single transaction.

          Good luck,

          Steve

          • 2. Re: Concurrency/CMP 2.x problem in Jboss
            Omar Belakhdar Newbie

            Thanks for your reply.
            Before writing my question I read all aspects concerning transactions.
            I tried in the past a same as you said (I mean with stateless session beans) but unfortunately it does work.

            I think what I need is an optimistic concurrency like the one supported in weblogic server and the most important data base servers like the one I'm using (Postgres uses multi-versionning appoach where writes don't block reads and reads don't block writes).

            Regards,

            Omar.

            • 3. Re: Concurrency/CMP 2.x problem in Jboss
              Steinar Overbeck Cook Newbie

              Locking is performed within JBoss. Upon entering the method, the entity ben is locked.
              Once the method call has finished, the TX is completed and other EJBs are allowed access to the same entity bean.

              Using "for...update" is really only usefull if you are accessing the same database from some other non-jboss application. In which case you must change you commit-option to either B or C.