Identify correct and incorrect statements or examples about the lifecycle of a Stateful Session Bean including the @PrePassivate and @PostActivate lifecycle callback methods and @Remove methods.
Stateful Session Beans maintain state, that is, they store data or information about a given client that has invoked them. SFSB clients can be anywhere, but all of that data about all of those clients has to be stored somewhere, and since a SFSB is a server side component, it's that application server, or more accurately, the EJB container, that must maintain all of this information about conversational clients.
Of course, if there are loads of clients invoking stateful session beans, then there's going to be loads of data to be stored on the server. To minimize the stress maintaining stateful clients places on an application server, the EJB container is allowed to take a Stateful Session Bean out of memory, and temporarily store the state of that SFSB until the client to which it is tied requests its services again. The process of storing the state of a Stateful Session Bean is known as passivation.
Of course, if the state of a bean is temporarily taken out of memory and places in some sort of persistence store, well, the time will come where the reverse will happen, that is, the EJB container must reassemble the SFSB, or un-passivate it. The process of un-passivating a Stateful Session Bean is known as activation.
For the most part, an EJB container doesn't have any problems passivating and subsequently activating Stateful Session Beans, especially if they are simply composed of primitive types and Serializable objects. However, if you've put some strange, fancy-dancy data type into your SFSB, and the JVM has no idea how to store or retrieve this crazy type of data, well, you're going to have to do some fancy footwork when the EJB container both passivates and activates your Stateful Session Bean.
To take evasive action when the EJB container is about to passivate your SFSB, all you have to do is write a method that performs your fancy footwork, and decorate that method with the @PrePassivate annotation.
To help the EJB container re-construct your Stateful Session Bean when the passivated bean is activated, you simply write your supporting code into a standard Java method, and then decorate that method with the @PostActivate annotation.
The semantics of PrePassivate and PostActivate are the same as the EJB 2.1 ejbActivate and ejbPassivate callback methods.
Stateful Session Bean Removal
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.
-pg 30 EJB 3.0 Simplified API