|Prev | Next||J2EETM Developer's Guide
createmethod.The EJB container instantiates the bean and then invokes the
ejbCreatemethods in the session bean. The bean is now ready to have its business methods invoked.
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 bean's
ejbPassivate method 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, moving it back to the ready stage, and then calls the bean's
At the end of the life cycle, the client invokes the
remove method and the EJB container calls the bean's
ejbRemove method. The bean's instance is ready for garbage collection.
Your code controls the invocation of only two life cycle methods-- the
remove methods in the client. All other methods in Figure 3-1 are invoked by the EJB container. The
ejbCreate method, for example, is inside the bean class, allowing you to perform certain operations right after the bean is instantiated. For instance, you may wish to connect to a database in the
ejbCreate method. (See the Database Connections chapter for more information.)
FIGURE 3-1 Life Cycle of a Stateful Session Bean
FIGURE 3-2 Life Cycle of a Stateless Session Bean
TOC | Index