Which must result in the destruction of a stateful session bean?

Which must result in the destruction of a stateful session bean?

Which must result in the destruction of a stateful session bean?

A.
A client calls an @Remove method and the method returns successfully.

B.
The server in which the stateful session bean was created is restarted.

C.
The stateful session bean participates in a transaction that is rolled back.

D.
The stateful session bean is chosen as a last recently used (LRU) victim for passivation.

Explanation:
While in the ready stage, the EJB container may decide to deactivate, or passivate,
the bean by moving it from memory to secondary storage. (Typically, the EJB container uses a
least-recently-used algorithm to select a bean for passivation.) The EJB container invokes the
method annotated @PrePassivate, if any, immediately before passivating it. If a client invokes a
business method on the bean while it is in the passive stage, the EJB container activates the
bean, calls the method annotated @PostActivate, if any, and then moves it to the ready stage.
Note:
At the end of the lifecycle, the client invokes a method annotated @Remove, and the EJB
container calls the method annotated @PreDestroy, if any. The beans instance is then ready for
garbage collection.
*When a stateful bean is passivated, the instance fields are read and then written to the secondary
storage associated with the EJB object. When the stateful session bean has been successfully
passivated, the instance is evicted from memory; it is destroyed.
*When a passivated bean instance times out or when a client invokes the method marked with
@Remove, the container may destroy the bean. Before destroying, the container will invoke the
method annotated with @PreDestroy.

Reference:The Java EE 6 Tutorial,The Lifecycles of Enterprise Beans



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Oscar

Oscar

why not B too?