7 Replies Latest reply on Sep 6, 2002 3:04 PM by Tim Fox

    how many instances of entity bean does JBoss hold?

    Tim Fox Master

      Can anyone answer this question:

      How many instances of a particular entity bean (eg the "John Smith" PersonEJB) does the container hold at any one time?

      For commit options A and B, I believe only one is held and access to the bean is controlled by a lock.

      For commit option C I am not sure.

      Please, please, please someone answer my question... since deadlocks even in commit option C are currently crippling my system.

      I need to stop these deadlocks.

      I am using 3.0.2

      Thankyou.

        • 1. Re: how many instances of entity bean does JBoss hold?
          Hezekiel Newbie

          This is probably far-fetched? but have you tried to set the configuration options regarding bean caching in standardjboss.xml file?

          • 2. Re: how many instances of entity bean does JBoss hold?
            Tim Fox Master

            I think I can answer my own question and it is not good news.

            It seems that jboss ensures there is only ever one entity bean identity instance in the container at once, even in commit option C.

            It also pessimistically locks ALL beans in the transaction, whether or not updated. (OUCH!)

            This results in huge numbers of deadlocks even for short transactions.

            My only option seems to be to replace the Pessimistic locking policy with effectively NO locking (actually use method only locking).

            This should alleviate the deadlocks, but because the entity state is not protected, ACID transactions are compromised.

            In order to gain back ACID transactions it seems I must use another layer of optimistic locking on top of jboss.

            Does this about right, or am I talking nonsense?

            I would like to hear how other people have coped with this, since I don't really see how an app can survive with this pessimistic locking in a production environment.

            • 3. Re: how many instances of entity bean does JBoss hold?
              Greg Turner Apprentice

              Timfox, Yes, I would say you are confused. This is a long and complicated subject so I will only point you in the right direction. First of all, you are confusing cache and pool. Pool is the pool or number of instances of an EJB class, without regard to state. So, if you have a CustomerEJB, you could have 50 instances to be able to handle 50 concurrent accesses to Customer. Then there is cache which is the data, There is only ever one copy of data in cache and the only question is if the data is in sync with the database and that is what commit options are for. So you have 50 CustomerEJB, one of which may be Fred and one of which may be Joe, and the others may be indeterminate at any one time. You should find your self a good EJB book that explains the life cycle of EJB, when the instances go from inactive to active, etc. The EJB spec explains the requirements for commit options. The conf/standardjboss.xml file is where you can set the number of instances in the pool and the commit options. The Quickstart Guide and Admin Guide explain how to change these options and in particular, how to change them on a per EJB class basis.

              • 4. Re: how many instances of entity bean does JBoss hold?
                Fusayuki Minamoto Apprentice

                The JBossBook 3.0 mentions this in pp.166-168.
                Miki

                • 5. Re: how many instances of entity bean does JBoss hold?
                  Georg Schmid Newbie

                  In jboss.xml you'll find a container configuration
                  called Instance Per Transaction ...
                  It uses a MultiInstanceInterceptor and the EJBMethodOnly lock. Thus you'll get one instance per transaction, and the EBs are only locked during the method call and not until the transaction completes.

                  Configure your entity beans to use this configuration.

                  HTH.

                  Georg

                  • 6. Re: how many instances of entity bean does JBoss hold?
                    Georg Schmid Newbie

                    In jboss.xml you'll find a container configuration
                    called Instance Per Transaction ...
                    It uses a MultiInstanceInterceptor and the EJBMethodOnly lock. Thus you'll get one instance per transaction, and the EBs are only locked during the method call and not until the transaction completes.

                    Configure your entity beans to use this configuration.

                    HTH.

                    Georg

                    • 7. Re: how many instances of entity bean does JBoss hold?
                      Tim Fox Master

                      Giorgio42 - thanks for your reply - this is exactly what I am looking for.

                      I had no idea this was actually documented somewhere - and I even paid for the documentation subscription some time ago - I feel very stupid now!

                      Looks like I was under the impression that the default configuration (ie one instance shared by transactions) and pessismistic locks - was the only configuration, and is clearly liable to deadlock in all but the simplest of real world situations.

                      Anyway, you have pointed me to what I require - an instance per transaction and only method locking.

                      I'll still need to apply optimistic locking on the application level, but that's not a big problem for me.

                      SGTurner - thanks for you reply too. With respect I'm well aware of the difference between the cache and the pool, and the ins and outs of the ejb life cycle, and the intricacies of commit options, but please forgive me for my ignorance of the configurability of JBoss. I simply thought the default configuration was the only configuration - I had no idea it was so flexible.

                      Thanks again, I shall now go off and actually read the documentation I paid for some months ago. :)