Chapter 2.  General EJB 3.0 Enterprise Bean Knowledge

Identify correct and incorrect statements or examples about the lifecycle of all 3.0 Enterprise Bean instances, including the use of the @PostConstruct and @PreDestroy callback methods.

Lifecycle Callbacks for Stateless Session Beans

Client View of a Session Bean

Addition of a new instance to the Stateless Session Bean Pool:

Addition of a new instance to the Stateless Session Bean Pool

Retrieving reference to Stateless Session Bean business interface from JNDI:

Retrieving reference to Stateless Session Bean business interface from JNDI

Servicing a business method:

Servicing a business method

Removing the Stateless Session Bean instance:

Removing the Stateless Session Bean instance

The following lifecycle event callbacks are supported for stateless session beans:

  • PostConstruct

    PostConstruct callbacks occur after any dependency injection has been performed by the container and before the first business method invocation on the bean.

    PostConstruct methods are invoked in an unspecified transaction context and security context.

  • PreDestroy

    PreDestroy callbacks occur at the time the bean instance is destroyed.

    PreDestroy methods execute in an unspecified transaction and security context.

NOTE. PostActivate and PrePassivate callbacks, if specified, are ignored for stateless session beans.

Lifecycle Callbacks for Stateful Session Beans

The life cycle of a stateful session bean (does not implement javax.ejb.SessionSynchronization):

The life cycle of a Stateful Session Bean

Stateful session beans support callbacks for the following lifecycle events: construction, destruction, activation, and passivation.

Retrieving reference to Stateful Session Bean business interface from JNDI:

Retrieving reference to Stateful Session Bean business interface from JNDI

Servicing a business method:

Servicing a business method

Passivating a Stateful Session Bean:

Passivating a Stateful Session Bean

Activating a Stateful Session Bean:

Activating a Stateful Session Bean

Servicing a @Remove method:

Servicing a @Remove method

The lifecycle event callbacks are the following. They may be defined on the bean class or an interceptor class for the bean.

  • PostConstruct

    PostConstruct methods are invoked on the newly constructed instance, after any dependency injection has been performed by the container and before the first business method is invoked on the bean.

    PostConstruct methods are invoked in an unspecified transaction and security context.

  • PreDestroy

    PreDestroy methods execute after any method annotated with the Remove annotation has completed.

    PreDestroy methods are invoked in an unspecified transaction and security context.

  • PostActivate

    This notification signals the instance it has just been reactivated.

    Its purpose is to allow stateful session beans to maintain those resources that need to be reopened during an instance's activation.

  • PrePassivate

    This notification signals the intent of the container to passivate the instance.

    Its purpose is to allow stateful session beans to maintain those open resources that need to be closed prior to an instance's passivation.

NOTE: The callbacks PreConstruct, PostDestroy, PreActivate, and PostPassivate were not introduced because there did not seem to be use cases that justified their introduction.

Lifecycle Callbacks for Message-Driven Beans

The life cycle of a Message Driven Bean:

The life cycle of a Message Driven Bean

Addition of a new instance to the Message-Driven Bean pool:

Addition of a new instance to the Message-Driven Bean pool

Servicing an onMessage(...) method:

Servicing an onMessage(...) method

Removing the Message-Driven Bean instance:

Removing the Message-Driven Bean instance

The following lifecycle event callbacks are supported for message-driven beans:

  • PostConstruct

    PostConstruct callbacks occur before the first message listener method invocation on the bean. This is at a point after which any dependency injection has been performed by the container.

    PostConstruct callback methods execute in an unspecified transaction and security context.

  • PreDestroy

    PreDestroy callbacks occur at the time the bean is removed from the pool or destroyed.

    PreDestroy callback methods execute in an unspecified transaction and security context.

NOTE: PostActivate and PrePassivate callbacks, if specified, are ignored for message-driven beans.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine