cache EJB Remote or Home interface?


EJB design: cache EJB Remote or Home interface?

  1. cache EJB Remote or Home interface? (6 messages)

    Hi all,

    I have a memory problem when I try to access my EJB (stateless) in JBoss from a servlet. I try to access from a servlet so I get the EJBHome and I cache it in a static variable.
       Every time the servlet is accessed I do the .create() method to access the EJB in the EJBHome interface.

       When this servlet (executing in iPlanetWeb Server 4.1, NOT in the same machine with JBoss) runs, it gets more and more memory, until the Web Server crashes. I have profiled it and the number of loades classes is always raised by one, every time I execute the servlet.

       If the EJBRemote is cached instead of EJBHome, so we don´t need to execute the .create() on every call to the servlet, this memory leak doesn´t happen.
        What happens here?

        Is there any problem caching the EJBRemote in the servlet? I think that I should cache the EJBHome because maybe the EJBCreate could do tasks like load-balancing, assign new EJB instances,...?
        Anybody can explain me this?
        or is this a JBoss problem?

            Jose R. Díaz
  2. cache EJB Remote or Home interface?[ Go to top ]

    I wouldn't suggest keeping a static reference to either kind of interface in a Servlet unless you keep it in the HttpSession. I believe a static member of a Servlet is not reentrant. I don't know if this causes your leak.

    In my opinion you should not cache the remote interface as it can be downloaded from different app servers during failover etc. so you would be skipping the "desired" initialization phase.

    I never thought about cacheing the Home but if you do it
    make sure that its in some state filled layer like HttpSession, instead of one copy for all users.
  3. cache EJB Remote or Home interface?[ Go to top ]

    I cache the home interface in Hashtable keyed against the JNDI name. The Hastable is contained inside a singleton which provides a method like getHomeInterface(String jndiName)

  4. Hi,

       Ok. I think it´s true I should cache the Home in a singleton, but I suppose to save only one for all the users, to cache it. I don´t want to do the JNDI lookup for every user.
       But why to execute "HOME.create()" is taking more and more memory in JBoss? Anybody knows?


              Jose R.
  5. Hai pranab ,

    I am interesting abt this issues.. I am also trying to Cache Home Interface . I am using JRun. anyway what is the best approach to cache Home Interface.. ?

    how u dealing with . i am trying to put all hom einterfaces in Hashtable and i am hosding on one SingletonClass out side Container. when i need i am getting those Singleon class an and calling create and getting Remote Interface ..

    What is th performance issue in Caching Home .. I thought these is no way to cahe RemoteIntf.. it is Remote Object .. ?

    Respond me if u have chance ..

  6. Testing sorry
  7. Hi ,

    I am also facing same problem with JRUN3.02 . I am also trying to cache Home Interface its memory going high after soem time. Caching Home interface is Right Way or Caching Remote Interface is right WAy ? Which is the best Design pattern.. ?

    One more interesting thing is

    I had two beans X and Y. X Home interface Extends from Y Home Interface . So there is no create in X Home Interface it is empty.. just empty .. It will use Y Home Interface.

    Y Home interface create method return YRemoteInterface .

    I lookup for X Home Interface and i am calling xHome.Create() it returning XInterface .. but the funnyes part is actually the object need to return YRemoteInterface.. . How ths X.Home is nothing buy YHome it return value is YRemoteInterface .. but it returning X Interface

    Is it spec says like that .. ?