remove is the method called by the client program when you dont need the stateful bean anymore...Once you call the remove method the container knows it has to discard the bean...at that point it calls the predestroy method to perform cleanup...So predestroy method will be called after remove method...
Thanks for reply According to me the purpose of PreDestroy method is that do some activity before destroying or removing bean instance.So PreDestroy should be called before Remove method. What is purpose of calling PreDestroy method when bean is already removed.
Joined: Mar 26, 2008
Purpose of pre-destroy is to perform cleanup operations. Its not to remove the bean. The bean is removed by the container when you call @Remove annotated method.Pre-destroy is just a callback listener method called before the bean is destroyed. @Remove is the method you call to indicate the container that you want the bean to be removed. So always the remove method will be called before pre destory method.
"The Remove annotation may be used to annotate a stateful session bean business method. Use of this annotation will cause the container to remove the stateful session bean instance after the completion (normal or abnormal) of the annotated method." source: JSR220-simplified
In EJB3, @Remove only applies to SFSB, not SLSB. There is no method-ready pool for SFSB's (SFSB's hold client-specific data).
The method annotated with @Remove is business method. The client must call this method to indicate that the client want to remove the steteful session bean. The container only know after the remove method is called the client want to remove the instance. after this the container will do the cleanup work in the preDestroy method.