ejbCreate in StateFullSessionBean

Discussions

EJB programming & troubleshooting: ejbCreate in StateFullSessionBean

  1. ejbCreate in StateFullSessionBean (3 messages)

    I have the following situation:
    My bean is stateful session bean
    No of instances in the pool is fixed to 2.
    Currently 2 clients have invoked business methods on the bean.
    If the 3rd client comes one of the beans state will be passivated and assigned to this client
    My question is when the 3rd client will come he will call create on Home object, this will lead to creation of EJBObject so since 2 bean instances have already been created , will ejbCreate be called on the bean and if yes then will it be called before passivation of one instance.Also if i need to pass parameters in create method how will it be stored in the bean instance, if ejbCreate is not called for the 3rd client?

    thanx
    kapil

    Threaded Messages (3)

  2. ejbCreate in StateFullSessionBean[ Go to top ]

    If you are using a stateful session bean, the EJB standard guarantees that ejbCreate() will be invoke for each client. Furthermore, each client will always have a separate Stateful Session Bean; Stateful Session Beans do not use instance swapping the way that Stateless Session Beans and Entity Beans do.

    To pool size for Stateful Session Beans has a different effect: it limites the number of Stateful Session Beans you have in memory. If you have 100 clients, you will have 100 Stateful Session Beans, but if your pool size is "2", only two of those beans will be in memory at any given time. If another client comes along, one of the existing beans will be saved to disk, and either:

    a) A new bean will be created from a brand new client.
    b) An existing Stateful Session Bean will be retrieved from disk and loaded back into memory for an existing client.

    Needless to say, if your Stateful Session EJB pool is too small, you will end up with a huge amount of disk swapping. Try to make the Stateful Session EJB pool size equal to the number of clients you expect to have under normal load conditions. If this is not practical (each you expect to have tens of thousands of concurrent clients), don't use Stateful Session Beans; design some other architecture.
  3. ejbCreate in StateFullSessionBean[ Go to top ]

    Thanx Paul... But as u stated below i have one problem.

    "If another client comes along, one of the existing beans will be saved to disk, and either:

    a) A new bean will be created from a brand new client.
    b) An existing Stateful Session Bean will be retrieved from disk and loaded back into memory for an existing client. "

    I am printing the entry points in my ejbCreate and ejbPassivate() method of my bean.I am using weblogic server 8.1.
    Actually when my third client calls create on home object, first ejbCreate is getting called and then ejbPassivate on bean. How is this happening because bean is getting initialized in ejbCreate with parameters i am passing and after that state of old clent is getting passivated.This is a bit confusing.
    Can you please help on this.

    regards
    kapil
  4. ejbCreate in StateFullSessionBean[ Go to top ]

    It could be that the server is passivating your client's EJB very quickly because the pool size is so small. Try increasing the pool size to something reasonable (like 100 beans) and see if the behavior goes away.