Examining the Life Cycle of a Message-Driven Bean

Figure 14.6 shows the life cycle of a message-driven bean instance.

Figure 14.6. Message-driven bean life cycle.


The following sequence describes the life cycle of a message-driven bean instance:

  • The bean instance's life cycle starts when the container decides to instantiate a bean instance. The container instantiates the bean using the newInstance() method and then calls the setMessageDrivenContext() and ejbCreate() methods. Now the instance is ready to process a message sent to its Destination by any client.

  • When a client sends a message to a Destination, the container selects one of its method-ready instances and calls the instance's onMessage() method.

  • The container decides to remove the bean instance. This could be because the container wants to reduce the number of instances in the method-ready pool. The container calls the ejbRemove() method of the bean instance.

Caution

You cannot rely on the container to call the ejbRemove() method. The container might not call ejbRemove() in the following scenarios: a shutdown or crash of the container, or a system exception thrown from the instance's method. If your instance frees up resources in the ejbRemove() method, those resources are not freed in the preceding scenarios. You should provide some mechanism to periodically clean up the unreleased resources.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.166.131