There are two events happen from container when client doesnt make any calls.
1) The first event is for short time, the conatainer will call ejbPassivate() method. 2) Second event is for long time, the container will call ejbRemove() method.
If my understanding is correct, short time reaches first while waiting for call and always container should call ejbpassivate() method. So, ejbRemove()method should never be called.
Yea, ejbRemove() will be called by the container on bean instance when the client invoke remove() method in the ejbObject of the stateful session bean. This will be called only once in the life cycle of a stateful session bean.
The difference between the two calls is not about time. ejbPassivate() is called by the container only when it is running short on resources(memory). If the server is not low on resources it will not bother to passivate a bean even though the bean has been around for a while. As for the ejbRemove() method, it gets called by the container when a bean has timed out. Timeout is not about how long the bean has been in the 'method ready' state, it is about how long the bean has been left idle. A bean could time out when the bean is in the 'method ready' state or when it has been passivated. If it is in the passivated state, then it gets removed without getting re activated.
Hope this helps.. You may want to refer to pg184 - 185 of HFEJB for more info. Cheers ! [ April 27, 2005: Message edited by: linoops ]
Though both ejbPassivate and ejbRemove are releasing resources they are not same by any means. When passivating the EJB container store/ persists the state of EJB and release resources. But removing is just like assign null into the reference. Meaning of removing passive EJB is removing the stored state of the EJB from the storage. Hope this helps
A followup question to Kris's post. Since ejbRemove is not called if the bean has been passivated, how can i make sure that something always happens before a bean dies ???
Also, what is typically done in the ejbRemove method?? (Haven't used ejb's much, so real world examples of what you do in the ejbRemove will help).
If the Bean is in Passive state on the server and client calls remove() then how will it behave? Will it activate the bean first and then call ejbRemove().
Regards,<br />Purvesh<br />SCJP, SCBCD, IBM Exam #486
This is really good question. One thing is sure that Container will not activate it for the sake of removing it and it also not a business method to activate it.
Yes Prashant. Its meaningless to activate the bean just for removing it. But what is there in EJB Specs for such scenario? Experts please provide your views. Thanks.
Regards,<br />Purvesh<br />SCJP, SCBCD, IBM Exam #486
Hi, It depends upon the bean type. If we talk about the stateful bean and the client calls remove when the bean is in passivate stage then ejbRemove won;t be called.
On the other hand if its an entity bean bean and the client call the remove then the container will first Activate the bean just it case the bean is having any cascade delete.
Cheers.
Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.