The Java EE 5 Tutorial

The Life Cycle of a Message-Driven Bean

Figure 20–5 illustrates the stages in the life cycle of a message-driven bean.

Figure 20–5 Life Cycle of a Message-Driven Bean

Diagram showing the life cycle 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 it has only two states: nonexistent and ready to receive messages.

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