The Java EE 6 Tutorial

The Lifecycle of a Message-Driven Bean

Figure 14–6 illustrates the stages in the lifecycle of a message-driven bean.

Figure 14–6 Lifecycle of a Message-Driven Bean

Diagram showing the lifecycle of a message-driven bean.

    The EJB container usually creates a pool of message-driven bean instances. For each instance, the EJB container performs these tasks.

  1. If the message-driven bean uses dependency injection, the container injects these references before instantiating the instance.

  2. The container calls the method annotated @PostConstruct, if any.

Like a stateless session bean, a message-driven bean is never passivated and has only two states: nonexistent and ready to receive messages.

At the end of the lifecycle, the container calls the method annotated @PreDestroy, if any. The bean’s instance is then ready for garbage collection.