mardi 19 mai 2015

Purposes of @Remove method in stateful EJB

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 http://ift.tt/1Adzp89 )

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?

Aucun commentaire:

Enregistrer un commentaire