when ejbRemove() is called?


EJB programming & troubleshooting: when ejbRemove() is called?

  1. when ejbRemove() is called? (2 messages)


    I have a simple EJB bean class.

    import javax.ejb.*;
    public class HelloBean implements javax.ejb.SessionBean
    private SessionContext ctx;

    public void ejbCreate()

    public void ejbRemove()

    public void ejbActivate()

    public void ejbPassivate()

    public void setSessionContext(javax.ejb.SessionContext ctx)

    public String hello()
    System.out.println("Hello World EJB");
    return "Hello World EJB return this time with SUNIL";

    When I invoke my client, it displays the string from ejbCreate() but the string inside the ejbRemove() method is not at all called. WHY?


    Threaded Messages (2)

  2. when ejbRemove() is called?[ Go to top ]

    since life cycle of bean instances are maintained by the container, you can not make sure, when ejbRemove() is called. But ejbRemove() method will be called by ejb container just before it destroys the bean instance. In your case the SOP inside ejbRemove() will be printed when container wants to destroy your instance, which you can not control.

  3. Well.... not quite :)[ Go to top ]

    If it is a stateful session bean, ejbRemove is called when the client calls remove() on the client side interface.

    ejbRemove() will *never* be called by a client on state*less* session beans.

    The container will *not* call ejbRemove if the bean throws a runtime exception, or the bean times out during passivation.

    In other words, you cannot guarantee that ejbRemove will always be called.

    Welcome to ejb :)