Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 652
stg Avatar asked Nov 10 '22 13:11

stg


1 Answers

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!

like image 64
Jagadish Sharma U Avatar answered Nov 15 '22 12:11

Jagadish Sharma U