I do understand, that calling a @Remove
annotated method will tell the EJB container, that the client do not need the instance of a stateful EJB any longer and that it can be removed after the call.
But in the Oracle JEE tutorial this method is used to "clean" the instance. See here for example:
@Stateful
public class CartBean implements Cart {
// ...
List<String> contents;
// ...
@Remove
public void remove() {
contents = null;
}
}
(from https://docs.oracle.com/javaee/6/tutorial/doc/bnbod.html )
The member List<String> contents;
is set to null
but I do not see any reason to do this. When the instance is dropped, won't it kill all those kind of referrences anyway?
I could imagine, that one need to perform some business tasks when the instance is released, but after the call of the @Remove
method it will more or less directly invoke some @PreDestroy
method afterwards where I could perform those tasks. So why do we have this special mechanism with the @Remove
method and not just sth like EJBContainer.remove(myBean)
Could you please clarify the purposes of the @Remove
annotation and/or give some comprehensible use-case examples where it is evident to see why we need this mechanism?
The Main Functionality of the @Remove and @PreDestroy are same.Even though by using the @Remove which is a marker annotation defined such that individual business EJB vendors have a flexibility to call their business functionality methods like releasing their customized process before closing other standard EJB transaction which usually done by @PreDestroy which actually destroys the state of the Bean.
Hope this Helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With