3 Replies Latest reply on Jun 28, 2003 8:02 PM by cryokeeper

    EJBHomeFactory in JBoss

    Leung Kam Lung Newbie


      After reading of the EJBHomeLocalFactory question posted on this forum
      I understand on how to use it. However, I can not understand is following:
      Since the EJBHomeLocalFactory is a singleton object and it saved the Home object of an EJB in a map. Thus only one copy of a particular Home object was saved in the map. I had a servlet that accesses the EJBHomeLocalFactory in its body to lookup a Home object. Jboss creates 10 copies of this servlet. For some reasons that 10 copies of this servlet are all used by users. Thus all 10 of these servlets call to the EJBHomeLocalFactory to get the same Home object (one particalar Home object).
      Here are my questions:
      1) Who get the Home object from the EJBHomeLocalFactory?
      2) Since there is only one copy of a particular Home object. Do all others servlet MUST WAIT until the current servlet, that acquired the Home object, releases it.
      3) What happen when 10 servlets all have the same Home object.

      Thank you in advance,

        • 1. Re: EJBHomeFactory in JBoss
          eclaudius Newbie


          If I understand your question correctly then the answer is that when you lookup the Home interface you are returned a reference to the singleton object. This lets you call the methods on the object but you do not own the object nor do you have a copy of it. You are simply using it. As far as waiting or not I imagine that it is a single threaded object so you would have to wait, but I'm guessing here since I havn't looked at the source code.

          Can somebody help us out here?


          • 2. Re: EJBHomeFactory in JBoss
            Leung Kam Lung Newbie

            Hi EClaudius,

            Thank you for replying to my question. The EJBHomeFactory is a single class and it is just plain old java class. Let say that there are five servlets they all get a instance of the EJBHomeFactory and lookup the same Home interface myEJBHome at the same time. At this time who get the myEJBHome interface first. Other servlets have to wait. This will slow down others servlets to access the myEJBHome interface. If all servlets access the myEJBHome interface directly using JNDI. Then the application server may have serveral instances of the myEJBHome in its memory and is ready to pass it along.


            • 3. Re: EJBHomeFactory in JBoss

              I do not think it matters. In a traditional singleton ONLY the getInstance() method is synchronized. Only one thread can be in that method at a time. The method is unblocked as soon as the calling thread leaves the method. Usually within <1 mill depending on how long it takes your singleton to initialize the first time.

              As for multiple threads using the same home interface: This should be OK. The home interface is thread safe. The remote/local home is only a factory. Whenever you call create, a new bean created from the pool and assigned to you. None of your threads should be holding up in the home interface (unless the bean pool is full when your calling a create or the finder method has to add a bean to the pool).